- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 01:59 AM
Hi,
Need a solution that for client side code, synchronous AJAX methods should not be used then how we can use some other thing like script include for the requirement.
Script: function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getReference('caller_id');
if (caller.vip == 'true')
{
g_form.setValue('urgency','1');
g_form.setValue('impact','2');
}
else
return;
//Type appropriate comment here, and begin script below
}
Please suggest me the solution that how this can be improved by not using g_form.getReference().
I have also tried this by using UI policy but still not getting any appropriate result.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 03:03 AM
Hi,
Try to add some logs,
var chkUserRole = Class.create();
chkUserRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCallerUserRole: function() {
var caller = this.getParameter('sysparm_caller');
gs.addInfoMessage('caller_sys_id...'+caller);
var vip = gs.getUser().getUserByID(caller).getRecord().getValue('vip');
gs.addInfoMessage('vip...'+vip);
return vip;
}
});
Client script as below,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
//return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('chkUserRole');
ga.addParam('sysparm_name','chkCallerUserRole');
ga.addParam('sysparm_caller',g_form.getValue('caller_id'));
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage('answer...'+answer);
if(answer=='1')
{
g_form.setValue('impact','2');
g_form.setValue('urgency','1');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 02:44 AM
Hi
Try with something like this :-
var gr = new GlideRecord("sys_user_has_role");
gr.addQuery("user",caller);
gr.query()
if(gr.next())
{
return gr.role.getDisplayValue();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 02:50 AM
Hi
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id",caller);
gr.query();
if(gr.next())
{
return gr.vip;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 02:57 AM
Hi omkar,
my script include:
var chkUserRole = Class.create();
chkUserRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCallerUserRole: function() {
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id",caller);
gr.query();
if(gr.next())
{
return gr.vip;
}
}
});
please take a look.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 02:58 AM
Hi
Yes its correct. Just tell me one thing. Is the check box of Client Callable ticked while createing a script include? If not you need to create a new script include. Tick it and then try once again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 03:15 AM
Yes it is ticked.
