Value vs. Label vs. sys_id

Lon Landry4
Mega Sage

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

1 ACCEPTED SOLUTION

Kristen Ankeny
Kilo Sage

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. 

View solution in original post

1 REPLY 1

Kristen Ankeny
Kilo Sage

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.