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

I'm glad you got your question answered. Thank you for participating in the community.


Community Alums
Not applicable

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.

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?

mauricio_paloma
Tera Expert

Now that the wiki is gone, where can I find that Best Practice article in the Docs?


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.