Hard coded sys_id

ravi2k
Kilo Contributor

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' });

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

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'


});


View solution in original post

10 REPLIES 10

bekfro
Kilo Sage

Thanks all! This is great information, however, the links in this article are outdated and no longer work. There is a ServiceNow KB:  KB0785129 that references this community thread.  Is there any way to update the links here to get the information provided?