- 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 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 09:20 PM
Thanks @Ankur Bawiskar , its working for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 04:26 AM
Use an onChange Catalog Client Script when Selected user changes, sending the newValue to a Script Include with a GlideAjax call.
The Script Include needs to query the user table for the selected user, then you can dot-walk to the State on the Location and return this value to the client, where it is evaluated and controls the visibility of the leave type variable. If you also want leave type to be hidden before a Selected user is selected, create a Catalog UI Policy or onLoad Catalog Client Script. If by 'variable set' you mean a multi-row, as opposed to single row, the variable will be hidden in the Add Row dialog window only, but shown on the display of the MRVS contents on the request form, RITM, ...