passing property to script include and getting back sys ids script help?

Kiddy1
Tera Contributor

Developer Community harshtimes ctomasi shloke04 explorenow

Aim:Need to remove hard coded sys_ids from client scripts

i have created a script include which take the properties and returns sysids

in the below script i have 3 sys ids i need to paas them by creating a property to script include and return back sys ids from script include,i need help on creating a script include

which takes multiple properties from client script and return sysids.

script include:

var Passing_Sys_Ids = Class.create();

Passing_Sys_Ids.prototype = Object.extendsObject(AbstractAjaxProcessor, {

Passing_Sys_Ids:function()

{

var answer;

var prop_name = this.getParameter('sysparm_name_in');

answer = gs.getProperty(prop_name);

return answer;

},

      type: 'Passing_Sys_Ids'

});

client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (isLoading || newValue == '') {

return;

}

    //Type appropriate comment here, and begin script below

var getSysIds = new GlideAjax('Passing_Sys_Ids');

getSysIds.addParam('sysparm_name','Passing_Sys_Ids');

getSysIds.addParam('sysparm_name_in',"domain1"); //domain1 is sys property which was created to store sys_id

getSysIds.getXML(sysid);

function sysid(response)

{

  var answer = response.responseXML.documentElement.getAttribute("answer");

  alert(answer);

}

if(g_user.hasRole('itil') && g_user.hasRole('DE') && !g_user.hasRole("admin")){

var   user = new GlideRecord('sys_user');

user.addQuery('sys_id',g_user.userID);

user.query();

while(user.next())

{

domain = user.sys_domain;

}

if(domain == b4d705920f061e00e316f77ce1050e80) // can i replace answer here?

{

g_form.setValue('assignment_group',b4d705920f061e00e316f77ce1050e93) ;//i need to remove hard coded sys ids from scripts

}

else

{

g_form.setValue('assignment_group',b4d705920f061e00e316f77ce1050e67);//i need to remove hard coded sys ids from scripts

}

}

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI Kids,



Use getMessage in client script and store this sys_id's in that message.



This is how we replace gs.properties in client script.



Thank you,


Ashutosh



Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


View solution in original post

16 REPLIES 16

getMessage() is the client side method of doing translations. It uses information in System UI> Messages. If you use it, you should also include the "key" (the argument passed in getMessage()) in the Messages field of your client script. If you fail to do that, you're losing performance while the system does a lookup for you.



The server side counterpart to getMessage() is gs.getMessage(), not gs.getProperty().


Perfect. I Missed it. I wanted to say that if we want to call sys id in server script then we use properties.



Thanks @Chuck


can we create


system ui >messages and use it in serverside ?



var sysid=gs.getMessage('name')?


Yes you can use it.



Please see below link by ctomasi


How to use gs.getMessage() to get the string translated?



Thank you,


Ashutosh



Matk Answer as correct, Helpful or like it.


Please Close this thread by marking appropriate answer as correct.



Thank you,


Ashutosh