- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 08:37 AM
Hi All,
I'm looking for some advice on how to achieve a dynamic field label. The field is an integer representing distance, I personally read distance in Miles, but this is obviously not a global preference. I've created a system property that handles the conversion from Miles -> Km and Km -> Miles. What I would like to do then is update the field label to read "Distance (Km)" or "Distance (Miles)" depending on the current sys_property value.
I know that a label CAN be change with client side script, weather it should be is another matter, thinking DOM manipulation best practice etc.
I know that the value of a property can be captured with a getProperty, but cannot use gs. in client side scripting......
How would others approach this?
Solved! Go to Solution.
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 08:44 AM
To capture the property, You need to write a display business rule and save it in a g_scratchpad variable.
In your display BR, add the following script
g_scratchpad.my_property = gs.getProperty('property_name');
And in your client script
g_form.setLabelOf('field_name', g_scratchpad.my_property);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 09:02 AM
A system property is a global preference and not at user level. It does not serve the purpose if you need to change it only daily basis. If you need to set this at user level, add a custom field on the user table and allow them to edit it according to their preference like the timezone, language etc. You could then determine this value in the display business rule by querying on current users preference and then set it using the client script via g_scratchpad.
The best place for this data to go is in the User Preference table but then you need to implement ways in which you could capture user data into this table and then to display it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2019 03:51 AM
Thank you for your assistance with this. I was running a 'before' 'query' business rule rather than a 'display' business rule, this is what was causing my issues!
I've run this as a system property as it is a global preference rather than a user by user preference. This is an imperial vs metric option, the general consensus is you live/work in a country that uses either or, therefore does not need to be a personal preference.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 08:42 AM
You need to use g_scratchpad in client script to read system property value.
Please see below for more on g_scratchpad.
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/app-store/good_practices/client_script/reference/r_ServerDataExampleScratchpad.html
Regards,
Sachin