I want to pass sys_id through the property ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 09:28 PM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 09:34 PM - edited 12-15-2022 09:35 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 09:36 PM - edited 12-15-2022 09:37 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 10:48 PM
@Pooja Khatri if your issue is fixed, please mark the relevant answer correct to close the thread
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 09:37 PM
Check video on that :