- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 08:49 PM
Hi Team,
We have two variables on catalog item 1.Requested for(reference to user table) 2 VIP customer(check box). Requirement is when anyone changes the name in requested for variable if that user is VIP customer we have to show VIP customer check box as true...in user table we have a field VIP customer can anyone help me in the on change client script or any other possible way
Regards
Shabbir
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 09:34 PM
Hello @Shabbir1 ,
You can create onChange client script on requested_for variable as below -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//please replace the field names as per your use case
var userDetails = g_form.getReference('requested_for');
if (userDetails.VIPfield == 'true') {
g_form.setValue('vip_checkbox', true);
}
//Type appropriate comment here, and begin script below
}
If my answer solves your issue, please mark it as Accepted ✔️and Helpful 👍 based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 09:34 PM
Hello @Shabbir1 ,
You can create onChange client script on requested_for variable as below -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//please replace the field names as per your use case
var userDetails = g_form.getReference('requested_for');
if (userDetails.VIPfield == 'true') {
g_form.setValue('vip_checkbox', true);
}
//Type appropriate comment here, and begin script below
}
If my answer solves your issue, please mark it as Accepted ✔️and Helpful 👍 based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 04:30 AM
Thank you so much @Vrushali Kolte it is working fine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 11:01 PM
Hi @Shabbir1 ,
Please try the below, tested and working in PDI
Onchange Catalog Client script on 'requested_by' field:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('requested_by', setVip);
function setVip(openedFor) {
if (openedFor.vip == 'true') {
g_form.setValue('checkbox2', true); //replace checkbox2 with the VIP checkbox backend name field
} else {
g_form.setValue('checkbox2', false); //replace checkbox2 with the VIP checkbox backend name field
}
}
}
Result:
VIP User selected:
Not a VIP User:
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 11:06 PM - edited 07-08-2024 11:08 PM
Hi @Shabbir1,
We can achieve this in two ways:
1. getReference
2. GlideAjax
The best practice is to use GlideAjax instead of getReference, as it can cause the user interface to freeze while the call is being completed, which can result in a poor user experience.
onChange Client Script on Requested For:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('Test'); //script include name
ga.addParam('sysparm_name', 'getVIPdetails'); //second parameter - function name in the SI
ga.addParam('sysparm_user', newValue);
ga.getXML(getData1);
function getData1(response) {
var answer1 = response.responseXML.documentElement.getAttribute('answer');
if (answer1 == 'true') {
g_form.setValue('<vip_field_name', true);
} else {
g_form.setValue('<vip_field_name', false);
}
}
}
Script Include (make sure the Client callable checkbox is set to true):
var Test = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getVIPdetails: function(){
try{
var grUser = new GlideRecord('sys_user');
var flag = false;
if(grUser.get(this.getParameter('sysparm_user'))){
flag = grUser.vip_field; //replace vip_field with vip_field_name
}
return flag;
} catch (ex) {
gs.info('Error:' + ex.string() + '\nLine:' + ex.lineNumber);
}
},
type: 'Test'
});
Mark the response correct and helpful if the answer assisted your question.