Script Include issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 03:25 AM
Hello Experts,
I want to make the description mandatory based on the caller's location if the caller's location is xyz then the description field on the incident form should be mandatory.
I have written on change client script and script include. but my script returned me null I am passing a boolean value from my script include. can anyone please guide me on why I am getting a null value I have pasted my script below. thank you.
Script include:
var CheckCallerLocation = Class.create();
CheckCallerLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocation:function()
{
var caller=this.getParameter('sysparm_user_name');
var gr=new GlideRecord('sys_user');
gr.addQuery('location.sys_id','bf86ffa797bbb990df62b3b6f053afef');
gr.addQuery('sys_id',caller);
gr.query();
var flag;
if(gr.next())
{
//return gr.location;
flag==true;
}
else{
flag==false;
}
return flag;
},
type: 'CheckCallerLocation'
});
onChange Client Script
var ga = new GlideAjax('global.CheckCallerLocation'); // HelloWorld is the script include class
ga.addParam('sysparm_name','getLocation'); // helloWorld is the script include method
ga.addParam('sysparm_user_name',newValue); // Set parameter sysparm_user_name to 'Bob'
ga.getXML(callBack); /* Call HelloWorld.helloWorld() with the parameter sysparm_user_name set to 'Bob'
and use the callback function HelloWorldParse() to return the result when ready */
alert("alert number 18");
// the callback function for returning the result from the server-side code
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("alert 22"+answer);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 03:30 AM
Hi Mark,
In Script include remove the == for setting a field. It is used for comparision.
Remove == and replace it with = (single equals to which is more of assignment)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 03:33 AM
Hello @Mark Wood
Can you try like below :
Script include:
var CheckCallerLocation = Class.create();
CheckCallerLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocation:function()
{
var location;
var flag;
var caller=this.getParameter('sysparm_user_name');
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',caller);
gr.query();
if(gr.next())
{
location = gr.getValue('location');
}
if (location == 'bf86ffa797bbb990df62b3b6f053afef'){
flag=true;
}else{
flag = false;
}
return flag;
},
type: 'CheckCallerLocation'
});
Client script :
onChange Client Script
var ga = new GlideAjax('global.CheckCallerLocation'); // HelloWorld is the script include class
ga.addParam('sysparm_name','getLocation'); // helloWorld is the script include method
ga.addParam('sysparm_user_name',newValue); // Set parameter sysparm_user_name to 'Bob'
ga.getXMLAnswer(callBack);
// the callback function for returning the result from the server-side code
function callBack(answer) {
var result = answer;
if(result == true){
//make field mandatory
}else {
//to do
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 03:36 AM
Thank you @Vishal Birajdar and @Jaspal Singh .