Solved: When we use current. and when g_form ? - ServiceNow Community

When we use current. and when g_form ?

Vinay Nimbalka1
Kilo Contributor

we can access the form variable using both "current" and "g_form" but what is the specific area of both? 

1 ACCEPTED SOLUTION

Ajaykumar1
Tera Guru

Hi,

current object is used to refer the currently opened record on a business rule, workflows and in some other server-side scripts.

The current object is automatically instantiated from the GlideRecord class. The current object's properties are all the fields for a record and all the GlideRecord methods. The property values are the values as they exist in the runtime environment.

It's a reference to the record you are in. Example. An Incident record.

On the other hand, g_form is an object of GlideForm class, it is used to access the currently opened form data.

The GlideForm client-side API provides methods for managing form and form fields, such as,

  • Retrieve a field value on a form
  • Hide a field
  • Make a field read-only
  • Write a message on a form or a field
  • Add options to a choice list
  • Remove options from a choice list

For more information refer below links.

The GlideForm (g_form) Class

current and previous

Mark If Correct/Helpful.

Regards,
Ajay

View solution in original post

5 REPLIES 5

Gowtham29
Tera Expert

HI,

Current will be used in server side scripts like workflow, business rules and g_form will be used in client scripts.

Hi Gowtham,

If your doubt is clear, please mark the appropriate answer as correct and remove the thread from the unanswered queue.

Thanks.

Regards,
Ajay

Ajaykumar1
Tera Guru

Hi,

current object is used to refer the currently opened record on a business rule, workflows and in some other server-side scripts.

The current object is automatically instantiated from the GlideRecord class. The current object's properties are all the fields for a record and all the GlideRecord methods. The property values are the values as they exist in the runtime environment.

It's a reference to the record you are in. Example. An Incident record.

On the other hand, g_form is an object of GlideForm class, it is used to access the currently opened form data.

The GlideForm client-side API provides methods for managing form and form fields, such as,

  • Retrieve a field value on a form
  • Hide a field
  • Make a field read-only
  • Write a message on a form or a field
  • Add options to a choice list
  • Remove options from a choice list

For more information refer below links.

The GlideForm (g_form) Class

current and previous

Mark If Correct/Helpful.

Regards,
Ajay

Tejal Zete
Giga Expert

Hi,

The GlideForm API provides methods to customize forms. GlideForm.js is the JavaScript class containing the methods. The global object g_form is used to access GlideForm methods. GlideForm methods are only used on the client.

These methods are used to make custom changes to the form view of records. All validation of examples was done using Client Scripts.

Some of these methods can also be used in other client scripts (such as Catalog Client Scripts or Wizard Client Scripts), but must first be tested to determine whether they will work as expected.

Following link provide more info and its methods.

https://developer.servicenow.com/app.do#!/training/article/app_store_learnv2_scripting_london_client_side_scripting/app_store_learnv2_scripting_london_the_glideform_g_form_class?v=london

you would use the current.variables.variablename and anything in requested item table by itself you would use current.variablename

Variables in current are the columns that are defined in the dictionary.xml file that support the database record. There is no way at runtime to add variables to the current record.

following thread provide info about current and previous

https://developer.servicenow.com/app.do#!/lp/new_to_servicenow/app_store_learnv2_scripting_istanbul_business_rule_scripts?v=london

 

Mark it helpful/correct if it helps you.

Regards,

Tejal