- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 05:26 AM
Hi,
The task is to get sysID of the record and put into another variable. I am getting the output as null via addInfoMessage.
Script Include
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("onChangeStChSysIDClass");
ga.addParam("sysparm_name", "onChangeStChSysIDFunction");
ga.addParam("sysid_key", newValue);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage("answer is " + answer);
g_form.setValue("standard_change_template_sys_id", answer);
}
}
Script Include
var onChangeStChSysIDClass = Class.create();
onChangeStChSysIDClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onChangeStChSysIDFunction:function(){
var keyClientScript = this.getParameter("sysid_key");
var userId_DB = "";
var userGR = new GlideRecord("std_change_template");
userGR.addQuery("sys_id", keyClientScript);
userGR.query();
if (userGR.next()) {
userId_DB = userGR.getValue("sys_id");
return userId_DB;
}
},
type: 'onChangeStChSysIDClass'
});
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:59 AM
yes please write that code in onchange client script.
g_form.getValue('standard_change_template')
as this is reference field it returns sysid by default.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:06 AM
@Community Alums are you facing any issue, is it working fine
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:30 AM
Try this
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("onChangeStChSysIDClass");
ga.addParam("sysparm_name", "onChangeStChSysIDFunction");
ga.addParam("sysparm_sysidkey", newValue);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage("answer is " + answer);
g_form.setValue("standard_change_template_sys_id", answer);
}
}
Script include
var onChangeStChSysIDClass = Class.create();
onChangeStChSysIDClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onChangeStChSysIDFunction:function(){
var keyClientScript = this.getParameter("sysparm_sysidkey");
var userId_DB = "";
var userGR = new GlideRecord("std_change_template");
userGR.addQuery("sys_id", keyClientScript);
userGR.query();
if (userGR.next()) {
userId_DB = userGR.getValue("sys_id");
return userId_DB;
}
},
type: 'onChangeStChSysIDClass'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:22 AM
Hi @Community Alums ,
your are passing the sysid to server and getting the same sysid. But script is correct i didn't see any error.
try below don't required script include
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.setValue("standard_change_template_sys_id", newValue); //newValue stores the reference sysid
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar