- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 04:03 AM - edited 10-03-2023 04:14 AM
Hi All,
I have a requirement Actually in record producer, i am using a Variable set , in that , three fields, " Selected user(Reference field), type of leave and time of period ", So here the field 'leave type' was only visible , when the user(Selected user field )with location( particularly state is one of WA or SA)?
Please help me to solve this
Thanks
Deepika
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 06:58 AM
your script include is not client callable
Script include
var Locationbased = Class.create();
Locationbased.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocation: function() {
var userID = this.getParameter('sysparm_user');
var returnID = '';
var user = new GlideRecord('sys_user');
if(user.get(userID)){
return user.location.state;
}
},
type: 'Locationbased'
});
Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(oldValue != newValue){
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('Locationbased');
ga.addParam('sysparm_name', 'getLocation');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer){
alert(answer);
answer = answer.toString();
if (answer == 'WA' || answer == 'SA')
g_form.setDisplay('type_of _period', true);
else {
g_form.setDisplay('type_of _period', false);
}
});
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 04:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 04:59 AM
so what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 05:19 AM - edited 10-03-2023 05:24 AM
@Ankur Bawiskar i have written this code but its not working
Script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 05:35 AM
It looks like maybe your Script Include does not have the Client callable box checked as the second line should be:
Locationbased.prototype = Object.extendsObject(AbstractAjaxProcessor, {
You can add alerts to the Client Script and gs.info lines to the Script Include to confirm that it is running, the value passed in from the client, the result of the GlideRecord, and the value that will be returned to the client.
It's always best to return something to avoid errors, so consider changing the end of the SI to something more like this:
if (user.next()) {
returnID = user.location.state;
}
return returnID;
},
type: 'Locationbased'
};