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
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

 

RaghavSh
Kilo 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();


Raghav
MVP 2023

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


Raghav
MVP 2023

Ankita19
Tera Guru
Tera Guru
Introduction to ServiceNow System Property ServiceNow System Property Tips and Tricks Hi All, Hope you all are doing fine. In today's tutorial, we will be looking for ServiceNow System Property and understanding some use cases for the same. Let's first try to understand ServiceNow System Property