- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 12:10 AM
Hi Frds, I don't want to use Hard coded sys_id in my below script, Instead of this I want to Create a system property to store the name of the record (not the sys_id) for easier manageability. The script can use gs.getProperty() to retrieve the record and use the sys_id. If the named record was not found, an error can be displayed appropriately. Pls help how to modify the script. var DB_Get_ServiceDeskArea = Class.create(); DB_Get_ServiceDeskArea.prototype = Object.extendsObject(AbstractAjaxProcessor, { getServiceDeskArea: function () { var id = this.getParameter('sysparm_assignment_group'); var encodedquery = "sys_id="+id.toString()+"^typeLIKE887a30d60f623100ec12c9cce1050e6f"; var gr_group = new GlideRecord('sys_user_group'); gr_group.addEncodedQuery(encodedquery); // type of group is Helpdesk gr_group.query(); if (gr_group.next()) { return gr_group.u_servicedesk_subarea.toString(); } return 'null'; }, type: 'DB_Get_ServiceDeskArea' });
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 04:49 AM
Hi Ravish,
I've build a full wiki page with vides around this exact subject.
System Properties Best Practices - ServiceNow Wiki
In your situation, create a property something like this:
my.default.user_type, with a value "YOUR GROUP TYPE HERE".
Then your script might look something like this (I made a couple changes to fix some issues you were about to run in to, like returning nothing instead 'null'.)
var DB_Get_ServiceDeskArea = Class.create();
DB_Get_ServiceDeskArea.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServiceDeskArea: function () {
var defaultType = gs.getProperty('my.default.user_type');
if (defaultType = '')
return;
var id = this.getParameter('sysparm_assignment_group');
var encodedquery = "sys_id="+id.toString()+"^type.name=" + defaultType;
var gr_group = new GlideRecord('sys_user_group'); gr_group.addEncodedQuery(encodedquery);
// type of group is Helpdesk gr_group.query();
if (gr_group.next()) {
return gr_group.u_servicedesk_subarea.toString();
}
return;
},
type: 'DB_Get_ServiceDeskArea'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 05:42 AM
I'm glad you got your question answered. Thank you for participating in the community.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2019 06:30 AM
Hi
How to add the multiple sys_ids on a single system properties.
For Example: i want to two types records(sys_id's) for different scenarios . those records(sys_id's) are stored in same table.
for that shall i go with two properties or we have any option to added both sys_ids in single property.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2023 07:43 AM
Is this a firm rule that all sys_ids needed in scripts should be stored in a sys_properties? I see tons of instances in the OOB code where sys_ids are coded in Script Includes. Let's say I want to reference the sys_id for the OOB Normal change model. Seems simple to just hard code the sys_id. Using the gs.getProperty in this case actually makes the code do more work. Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2017 11:21 PM
Now that the wiki is gone, where can I find that Best Practice article in the Docs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2017 01:30 AM
Hi Mauricio,
you can find them in the developer docs portal: https://developer.servicenow.com/app.do#!/catlist/Technical%20Best%20Practices?v=jakarta or by searching "Best Practices" on the docs site.