- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 11:56 PM
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
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 12:04 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 12:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 01:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 04:01 AM
Since the properties aren't changing, you don't need to look them up in the script include, you can pass them via a display business rule. Just don't forget to pass the display value also! Passing the sys_id and then using it in g_form.setValue() means you'll just have to do a second (implicit) trip to the server to get the display value for that group.
Since the properties aren't changing, you don't need to look them up in the script include, you can pass them via a display business rule. Just don't forget to pass the display value also! Passing the sys_id and then using it in g_form.setValue() means you'll just have to do a second (implicit) trip to the server to get the display value for that group.
Display business rule:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.domain1 = gs.getUser().getDomainID();
// Use a property to hold the group1 name
var name1 = gs.getProperty('my.assignment_group1'); //use the real property name
g_scratchpad.group1 = {
"sys_id" : getGroupID(name1),
"display_value" : name1
}
var name2 = gs.getProperty('my.assignment_group2');
g_scratchpad.group2 = {
"sys_id" : getGroupID(name2),
"display_value" : name2
}
function getGroupID(grpName) {
var grp = new GlideRecord('sys_user_group');
if (grp.get('name', grpName)) {
return grp.getValue('sys_id');
}
return;
}
})(current, previous);
Client script:
// Your GlideAjax code here (unchanged)
if (domain == g_scratchpad.domain1) {
g_form.setValue('assignment_group', g_scratchpad.group1.sys_id, g_scratchpad.group1.display_value);
} else {
g_form.setValue('assignment_group', g_scratchpad.group2.sys_id, g_scratchpad.group2.display_value);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 08:17 AM
if it is for catalog client script how can we specify the table ?