I am unable to use getXMLWait in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 10:23 PM
Hi Team,
I have to restrict user to submit catalog item if has more then 3 asset .
I am calling Script include in onSubmit script. I am using getXML method with callback function(Asynchronous).
I have written return false in onSubmit client script. As scoped application doesn't support getXMLWait I am unable to make Synchronous
call and stop user from submitting the form.
Client script -
var requested_for = g_form.getValue('requested_for');
var user = '';
if (requested_for != '') {
user = requested_for;
} else
user = requester;
//alert(user);
var ga = new GlideAjax('Modeldetails');
ga.addParam('sysparm_name', 'returnDetails');
ga.addParam('sysparm_caller_id', user);
ga.addParam('sysparm_staus', NeworOld);
ga.getXML(function(response) {
var count = response.responseXML.documentElement.getAttribute("answer");
// var country = ga.getAnswer().toString();
//alert('country: ' + country);
if (count == "No") {
g_form.showFieldMsg("is_this_a_new_or_replacement", "Sorry, you have exceeded the limit of 3 model per user. Please contact your local IT Team for further instructions", 'error', true);
return false;
}
});
Script include-
returnDetails: function() {
var userId = this.getParameter('sysparm_caller_id');
//var NeworOld = this.getParameter('sysparm_staus');
var count = 0;
var gr = new GlideRecord("alm_hardware");
gr.addQuery("model", "41ce0cb2974abd584649b0d3f153af8b"); // sys id of asset
gr.addQuery("assigned_to", userId);
gr.query();
while (gr.next()) {
count++;
}
if (count >= 3) {
return "No";
} else {
return "Yes";
}
},
How can we achieve it please suggest me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 12:37 AM - edited 11-03-2023 12:45 AM
Hi @lucky24
I faced the same issue few days ago. I used scratchpad and getXmlAnswer to solve this :
function onSubmit() {
if (g_scratchpad.isFormValid)
return true;
var requested_for = g_form.getValue('requested_for');
var user = '';
if (requested_for != '') {
user = requested_for;
} else
user = requester;
//alert(user);
var ga = new GlideAjax('Modeldetails');
ga.addParam('sysparm_name', 'returnDetails');
ga.addParam('sysparm_caller_id', user);
ga.addParam('sysparm_staus', NeworOld);
ga.getXMLAnswer(setAnswer);
return false;
function setAnswer(answer) {
var count = answer;
if (count == "No") {
g_form.showFieldMsg("is_this_a_new_or_replacement", "Sorry, you have exceeded the limit of 3 model per user. Please contact your local IT Team for further instructions", 'error', true);
return false;
} else {
g_scratchpad.isFormValid = true;
var actionName = g_form.getActionName();
g_form.submit(actionName);
return true;
}
}
}
Regards,
Piyush Sain

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:01 AM
Hi,
As others already have stated, GlideAjax and onSubmit client script is a combination that will never work, because of the timings in these processes.
In this case, it sounds like you could instead implement the checking when the user is selecting assets?
An onChange Client script will work to notify the user and correct the selection before submitting the form.
(assuming there is a list collector, or something that allows for counting of records selected)