Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

MadhuriGudiseva
ServiceNow Employee
ServiceNow Employee

Here an example how to get dynamic Sys_id   with ajax in serviceNow

You Have to create script include named getRecordSysIdByName and then you can call it in your controller or your ui page

var getRecordSysIdByName = Class.create();

getRecordSysIdByName.prototype = Object.extendsObject(AbstractAjaxProcessor,{

  file: function(){

  return this.getSysId('sys_attachment');

  },

  css: function(){

  return this.getSysId('content_css');

  },

  uiPage: function(){

  return this.getSysId('sys_ui_page');

  },

  getSysId: function(tableName){

  var recordName = this.getParameter('sysparm_record_name');

  var ga = new GlideRecord(tableName);

  ga.get('name',recordName);

  gs.log('sys id: '+ga.sys_id);

  return ga.sys_id;

  }

});

in your controller:

var pageName = "test_template_menu";

  var ga = new GlideAjax('getRecordSysIdByName');

      ga.addParam('sysparm_name', 'uiPage');

      ga.addParam('sysparm_record_name', pageName);

      ga.getXMLWait();

  $scope.uiPage = {

  name: pageName,

  sys_id: ga.getAnswer(),

  url: 'ui_page.do?sys_id='+ga.getAnswer()

  };

Version history
Last update:
‎12-17-2014 01:47 PM
Updated by: