Difference between g_form.getValue and g_form.getUniquevalue

Khaled RAJHI
Tera Contributor

Hi community,

 

what is the difference between g_form.getValue and g_form.getUniquevalue ?

3 ACCEPTED SOLUTIONS

Maddysunil
Kilo Sage

@Khaled RAJHI 

In ServiceNow, both g_form.getValue() and g_form.getUniqueValue() are client-side JavaScript methods provided by the GlideForm API (g_form) for working with form fields. However, they serve slightly different purposes:

g_form.getValue(fieldName):

  • This method is used to retrieve the display value of a field on the form
  • .var fieldValue = g_form.getValue('field_name');

     

 

  • g_form.getUniqueValue():

    • This method is used to retrieve the unique identifier (sys_id) of the current record.
    • var uniqueValue = g_form.getUniqueValue();
    • In summary, g_form.getValue() is used to retrieve the display value of a specific field on the form, while g_form.getUniqueValue() is used to retrieve the unique identifier (sys_id) of the current record. Depending on your use case, you would choose the appropriate method

      Kindly mark helpful/accepted if it helps you.

View solution in original post

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

 g_form.getUniquevalue() does not require you to pass any argument, and it returns the sys id of the current record.

 g_form.getValue('<field name>') -> this requires you to pass the field that you want to read , and it returns the value of that field on the form.

-Anurag

View solution in original post

Service_RNow
Mega Sage

Hi @Khaled RAJHI 

getValue() and getUniqueValue()
Both getValue() and getUniqueValue() will return a value from the GlideRecord upon which they're called.

getUniqueValue() accepts no arguments, and simply returns the primary key (the sys_id) of the record.

getValue() on the other hand, can return the value from any table column (including sys_id). It accepts one argument - a field name, and will return the value therein.

Please mark answer correct/helpful based on Impact

View solution in original post

3 REPLIES 3

Maddysunil
Kilo Sage

@Khaled RAJHI 

In ServiceNow, both g_form.getValue() and g_form.getUniqueValue() are client-side JavaScript methods provided by the GlideForm API (g_form) for working with form fields. However, they serve slightly different purposes:

g_form.getValue(fieldName):

  • This method is used to retrieve the display value of a field on the form
  • .var fieldValue = g_form.getValue('field_name');

     

 

  • g_form.getUniqueValue():

    • This method is used to retrieve the unique identifier (sys_id) of the current record.
    • var uniqueValue = g_form.getUniqueValue();
    • In summary, g_form.getValue() is used to retrieve the display value of a specific field on the form, while g_form.getUniqueValue() is used to retrieve the unique identifier (sys_id) of the current record. Depending on your use case, you would choose the appropriate method

      Kindly mark helpful/accepted if it helps you.

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

 g_form.getUniquevalue() does not require you to pass any argument, and it returns the sys id of the current record.

 g_form.getValue('<field name>') -> this requires you to pass the field that you want to read , and it returns the value of that field on the form.

-Anurag

Service_RNow
Mega Sage

Hi @Khaled RAJHI 

getValue() and getUniqueValue()
Both getValue() and getUniqueValue() will return a value from the GlideRecord upon which they're called.

getUniqueValue() accepts no arguments, and simply returns the primary key (the sys_id) of the record.

getValue() on the other hand, can return the value from any table column (including sys_id). It accepts one argument - a field name, and will return the value therein.

Please mark answer correct/helpful based on Impact