- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2023 01:48 PM - edited ‎03-01-2023 01:51 PM
Howdy,
This question is related to client & server side scripting within the ServiceNow platform.
I have not detected common behavior related to when to use the following in a variable:
1. value
2. label
3. sys_id
Typically, I solve this issue by trying each of the three until one works...
Are there any rules related to when best to use one of the following in a variable?
- value
- label
- sys_id
Thanks for your help & time,
Lon
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2023 01:56 PM
If you're dealing with a reference field, value and sys_id will be similar. However, the value can possibly have more overhead coming with it. By label, do you mean "getDisplayValue"? If so, this is what is user visible for a reference field. So, if my display field for incident is the number column, if I am looking at the form, then I will see the incident number in a reference field, not the sys_id.
In general, I tend to use the value of a field. In some cases, if it is a reference, it works best to stringify value (g_form.getValue('my_field') + ''). As to which is best to use, it will be largely dependent on the logic you are attempting to execute.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2023 01:56 PM
If you're dealing with a reference field, value and sys_id will be similar. However, the value can possibly have more overhead coming with it. By label, do you mean "getDisplayValue"? If so, this is what is user visible for a reference field. So, if my display field for incident is the number column, if I am looking at the form, then I will see the incident number in a reference field, not the sys_id.
In general, I tend to use the value of a field. In some cases, if it is a reference, it works best to stringify value (g_form.getValue('my_field') + ''). As to which is best to use, it will be largely dependent on the logic you are attempting to execute.