Cannot use getReference method on client script , Glide ajax is the other way

Rahul84
Tera Contributor

Hi @Ankur Bawiskar /Team,

Facing one challenge to use getReference method on client script. I know the other way is to use Glide ajax call.

But I have a display business rule and have a g_scratchpad variable. 

I am having reference field "abc" on a table on which my onLoad client script is written and this "abc" field refers to other field that is having a manager field. I want the value of this manager field and needs to compare this with my g_scratchpad variable.

Pls let me know how can I use this on my client script instead of getRefernce. If Glide ajax is the way so pls provide me the logic and script for reference , how can I call my display BR on client script.

Thanks

21 REPLIES 21

Krupamayee
Kilo Expert

Hi ,

 

The below should work:

function onLoad() {

var manager= g_form.getReference('abc', doAlert); // doAlert is our callback function
}

function doAlert(manager) { 
if (manager.sys_id == g_scratchpad.manager1) { //return the manager sys_id in scratchpad variable

alert('Yes the values are same');
} else {


}
}

Please mark the answer correct and helpful if it resolved your issue,in case of any questions,please reply back.

-Krupa.

Hi,

We have the restriction to use getreference method in client script . Client script won't allow to save the changes using getreference

Thanks

Krupamayee
Kilo Expert

Hi Utkarsh,

Understood, could you please paste a screenshot of abc field/elaborate " this "abc" field refers to other field that is having a manager field."?

 

-Krupa.

Krupamayee
Kilo Expert

Hi,

 

As per my understanding I have taken a scenario here,

To check if "caller's manager' and 'assigned to manager' are same on incident form

1)Business Rule-gscratchpad variable which returns assigned to manager

find_real_file.png

2)Client script running On load on Caller field:

Passing the caller info to Script include and we will get the manager info of caller and validate

Client script(On Load):

function onLoad() {

var user = g_form.getValue('caller_id');
var getNames = new GlideAjax('PortalAjaxUtils');
getNames.addParam('sysparm_name', 'getManager');
getNames.addParam('sysparm_user', user); //Preet

getNames.getXMLAnswer(getAnswer);
}

function getAnswer(answer) {
answer = JSON.parse(answer);
if (g_scratchpad.user1 == answer.manager) {
alert('yes assigned to manager and caller manager are same');
}

}

find_real_file.png

 

3)Script Include which will return caller manager to client side

getManager: function() {
var user = this.getParameter('sysparm_user');
var retRes = {};

var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', user);
gr.query();
if (gr.next()) {
retRes.manager = gr.manager + '';

 


}
return new JSON().encode(retRes);
},

type: 'PortalAjaxUtils'
});

find_real_file.png

 

 

It prints yes,if assigned to manager and caller manager are same:

find_real_file.png

 

Please mark the answer correct and helpful ,if it resolved your issue. Feel free to ask questions if you have any.

-Krupa