Difference between value and display value

Khaled RAJHI
Tera Contributor

Hello everyone,

what is the difference between value and display value of a field ?

Could anyone explain to me to understand this particularity

I want to use g_form_setValue to set the value of assignment group to Hardware when the short description field contain 'disk', onSubmit

I need assistance to correct the query or missing parameter in the query, thank you

 
function onSubmit() {
 var short_description = g_form.getValue('short_description');
 var shdes = short_description.toUpperCase();
   if (shdes.includes("DISK"))
   {
  g_form.setValue('assignment_group','Hardware' );
   } }
1 ACCEPTED SOLUTION

Hello @Khaled RAJHI ,

 

Certainly! In the `g_form.setValue` function in ServiceNow, the third parameter (`displayValue`) is optional. The basic syntax is as follows:

 

g_form.setValue(fieldName: string, value: string, displayValue: string);

However, in many cases, you might not need to explicitly provide the `displayValue`. The `displayValue` parameter is typically used when you want to set both the value (sys_id) and the corresponding human-readable label at the same time.

 

In your specific scenario of setting the assignment group based on a condition, you are only interested in setting the sys_id of the assignment group based on the value associated with the condition. Therefore, you provide only the `fieldName` and `value` parameters.

 

If you had the display value and wanted to set both the sys_id and the display value simultaneously, you would include the third parameter:

g_form.setValue('assignment_group', 'sys_id_of_hardware_group', 'Hardware');

In your case, since you are setting the value programmatically based on a condition, you can omit the `displayValue` parameter if you don't need to set it explicitly.

 

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

View solution in original post

9 REPLIES 9

Brad Bowman
Kilo Patron
Kilo Patron

Assignment group is likely a reference type field, so the value of the field is a sys_id, whereas the display value of the field is the group name, like 'Hardware'.  In your setValue command, use the sys_id of the Hardware group instead of the name.

Prathamesh G
Kilo Sage
Kilo Sage

Hello @Khaled RAJHI,

 

Please refer to the below attached link to set the Assignment group (i.e. any reference field):

https://www.servicenow.com/community/developer-articles/setvalue-reference-fields-variables-use-the-...

 

Or you can also do this using after/before insert Business Rule to set any reference field value.

 

If the above answer resolve your issue, Please mark the solution as 'Accepted Solution' and also marked it as 'Helpful'.

 

Thank You!

Prathamesh.

Aniket Chavan
Tera Sage
Tera Sage

Hello @Khaled RAJHI ,

The basic difference between `value` and `display value` concepts is described below.

  • Value: The actual data stored in the database, often represented by a unique identifier (sys_id). For example, in your case the sys_id of the 'Hardware' group.
  • Display Value: In the context of a reference field, it's what you see in the dropdown or on the form. For example, the group name 'Hardware'.

Now, let's address your specific issue with setting the assignment group using `g_form_setValue`:
onSubmit Client Script:

function onSubmit() {
    var short_description = g_form.getValue('short_description');
    var shdes = short_description.toUpperCase();

    if (shdes.includes("DISK")) {
        // Set the assignment group using the sys_id (value) instead of the display value
        // Replace 'Hardware' with the actual sys_id of the 'Hardware' group
        g_form.setValue('assignment_group', 'sys_id_of_hardware_group');
    }
}

In the code above, replace `'sys_id_of_hardware_group'` with the actual sys_id of the 'Hardware' group. You can find this value by navigating to the 'Hardware' group record and looking at the URL, or  right click and "copy sys_id".

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

Many thanks @Aniket Chavan it's working fine now

Just a little question, in the command syntax description, there are 3 parameters to define fieldName, Value and dispalyValue <g_form.setValue(fieldName: string, value: string, displayValue: string)> but we put only two parameters

g_form.setValue('assignment_group', 'sys_id_of_hardware_group');

Could you please explain why do we limited only to two param ?