Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

I want to pass sys_id through the property ?

Pooja Khatri
Tera Contributor

In the below script , instead of passing the sys_id of the ITIL role directly I want to pass it through property . How can I implement this functionality?

 

Script : 

 

var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('user', current.manager.toString());
userRole.addQuery('role', 'db6d5371bd2230003c098cddac3d0741'); // sys_id of itil role
userRole.query();
if (!userRole.next()) {
userRole.initialize();
userRole.user = current.manager.toString();
userRole.role = 'db6d5371bd2230003c098cddac3d0741'; // sys_id of itil role
userRole.insert();

4 REPLIES 4

Ankita19
Tera Guru

Hi,

 In sys_properties.list you can create new property and  pass sys_id in value field and can use by gs.getProperty() in your code.

 

Ankita19_0-1671168935363.png

 

Raghav Sharma24
Giga Patron

Create a property in sys_properties table, with the required name, string type and in value paste the sys_id.

 

After that call that property in your code as below:

 

var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('user', current.manager.toString());
userRole.addQuery('role', gs.getProperty('property_name')); // sys_id of itil role
userRole.query();
if (!userRole.next()) {
userRole.initialize();
userRole.user = current.manager.toString();
userRole.role =gs.getProperty('property_name') ; // sys_id of itil role
userRole.insert();

@Pooja Khatri if your issue is fixed, please mark the relevant answer correct to close the thread

Ankita19
Tera Guru
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.