- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 08:04 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 01:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 08:25 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 08:30 AM
Hello @Khaled RAJHI,
Please refer to the below attached link to set the Assignment group (i.e. any reference field):
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 09:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 01:18 AM
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 ?