- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 04:29 AM
Hi, I would like to know why the code doesn't work for me? What I need to do is as soon as I open an incident and put in the caller a client who is a VIP, then the priority automatically changes to 1. This is important as soon as I open before I save
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 08:10 AM - edited 11-20-2023 08:11 AM
Try this updated script, I tested this in my PDI, it is working fine.
Client Callable Script Include:
var CustomUserUtils = Class.create();
CustomUserUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkVIPFlag: function() {
var caller = this.getParameter("sysparm_caller");
var usrGr = new GlideRecord('sys_user');
if (usrGr.get("sys_id", caller)) {
return usrGr.getValue('vip') + '';
}
return '0';
},
type: 'CustomUserUtils'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getValue('caller_id');
var uGa = new GlideAjax('CustomUserUtils');
uGa.addParam('sysparm_name', 'checkVIPFlag');
uGa.addParam('sysparm_caller', caller);
uGa.getXMLAnswer(setPriority);
}
function setPriority(answer) {
if (answer == '1') {
g_form.setValue("impact", "1");
g_form.setValue("urgency", "1");
}
}
Result:
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:58 AM
I can't getReference due to system constraints, I need such a way glide ajax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 08:27 AM - edited 11-20-2023 08:30 AM
Hi @yardenKrispel try this below code while onChange of caller field to VIP user then the priority will change to 1
client Script: Onchange
field Name : caller
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('myScriptUtils');
ga.addParam('sysparm_name', 'checkVipUser');
ga.addParam('sysparm_caller_sys_id', newValue); //newValue is caller
ga.getXML(ValidateVipUser);
function ValidateVipUser(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='true') {
g_form.setValue('priority', 1);
g_form.setValue('urgency', 1);
g_form.setValue('impact', 1);
}
Script Include: make sure client callable is true
var myScriptUtils = Class.create();
myScriptUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkVipUser: function() {
var caller = this.getParameter('sysparm_caller_sys_id');
var gr = new GlideRecord('sys_user');
gr.get(caller);
return gr.vip;
},
type: 'myScriptUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 08:10 AM - edited 11-20-2023 08:11 AM
Try this updated script, I tested this in my PDI, it is working fine.
Client Callable Script Include:
var CustomUserUtils = Class.create();
CustomUserUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkVIPFlag: function() {
var caller = this.getParameter("sysparm_caller");
var usrGr = new GlideRecord('sys_user');
if (usrGr.get("sys_id", caller)) {
return usrGr.getValue('vip') + '';
}
return '0';
},
type: 'CustomUserUtils'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getValue('caller_id');
var uGa = new GlideAjax('CustomUserUtils');
uGa.addParam('sysparm_name', 'checkVIPFlag');
uGa.addParam('sysparm_caller', caller);
uGa.getXMLAnswer(setPriority);
}
function setPriority(answer) {
if (answer == '1') {
g_form.setValue("impact", "1");
g_form.setValue("urgency", "1");
}
}
Result:
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 01:29 AM
its work! thank you so much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 08:38 AM
The reason it is not working for you based on your original question is because you have the Client Script setup to run "onLoad" instead of "onChange" of the Caller field. So when the script runs, you more than likely do not actually have a Caller set so your line 6 fails and never attempts to set the Priority field. When you set a Caller, the script will never run. So that is your first and most important error.
And by the way, as @AnveshKumar M has in his sample script, you should NOT be setting the value of Priority directly, but set the values of Impact and Urgency as they are used to calculate the Priority.
You keep saying you can't use getReference "due to system constraints", but that is inaccurate/misleading. getReference "can" be used, BUT it depends on what your REQUIREMENTS are. You have 2 different screenshots, one showing the "regular" fulfiller UI and the other looks like from a Workspace. Where is this Client Script expected to be run from? And based on that answer, that is where the constraint is coming from.