Martin Ivanov
Giga Sage
Giga Sage

Problem

ServiceNow scripting best practices recommend to avoid hardcoding strings in the code. One of the options to avoid that is to move them to system property and just retrieve the value in the code. (read more about strategies to avoid hardcoded values here).

 

Working with system properties might be annoying and repetitive task, though. And it is also prone to errors.

Errors may happen during the property name copy-paste or you can mistype the value retrieval statetement - gs.getProperty('property_name');

 

Solution

I had to script something today, which involved a bunch of properties and I created a simple UI action to copy the script usage to the clipboard. 

 

Example

Let's take property that I created for my previous article:

MartinIvanov_0-1676040040486.png

Usual flow will be:

  • go to the property definition
  • copy the property name
  • go to the target script
  • type var defaultAssignee = gs.getproperty('')*;
  • paste the propety name inside the quotes

With this little sugar, it is reduced to:

  • go to our sys_property
  • click 'Copy Script Usage'
  • paste wherever needed in the code

MartinIvanov_0-1676041986306.png

 

You can download the tool from the Share.

 

If you find this article useful, hit the like button and consider subscribing to my content.

Please feel fee to reshare with your network as well.

 

Thanks for reading!

 

Martin Ivanov

Community MVP 2023

Developer MVP 2023

 

*Thanks for noticing! Yes, I know I have a typo in gs.getproperty('');, this is to show that typos hapeen all the time 🙂

Comments
sidr
Tera Explorer

when an incident move to Inprogress state then how to create 100 user information record ? 

Version history
Last update:
‎02-10-2023 08:18 AM
Updated by:
Contributors