- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-21-2018 09:20 AM
Hi,
I may well not be doing this correctly, but I am trying to run an onChange client script to assign the ci to a field from the user record.
So I am
var user = g_form.getValue('u_requestor'); //Get the current user
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery("assigned_to", user);
--- this works fine with gr.next and setting the value.
But when I just add a another addQuery it stops working.
var user = g_form.getValue('u_requestor'); //Get the current user
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery("assigned_to", user);
gr.addQuery("u_type", "!=", monitors);
Any ideas?
Dan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-21-2018 12:06 PM
Hi Dan,
As mentioned earlier "Glide Record" usage in client script is not a good practice.
You should easily be able to convert your code into a GlideAjax call and/or getReference(callback) function, depending on the need of the requirement.
var ga = new GlideAjax('script_include_name');
ga.addParam('sysparm_name', 'function_name');
ga.addParam('sysparm_user', g_form.getValue('u_requestor'));
ga.getXML(mycallback);
function mycallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'yes') { //assuming you are returning yes as answer from script include
//Do logic here for the form, based on the response
}
}
// Script Include
function_name: function() {
var answer ='';
var user = this.getParameter('sysparm_user');
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery("assigned_to", user);
gr.addQuery("u_type", "!=", 'monitors');
gr.query();
while(gr.next()){
//do the logic here and set the answer variable to a value which you will use in the client slide.
answer = //Do the logic here...
}
return answer;
}
Please mark the response to the query helpful or correct, based on the impact of the response.
Thanks
IP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-21-2018 12:16 PM
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-26-2018 02:03 AM
Thanks all - really helpful.