g_form.setValue() fails inside getXML()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 12:06 PM
I'm forced to call global.AbstractAjaxProcessor to query some data from the client's onSubmit() handler. The data returns okay, but I need to set a field value with the data to submit it. setValue() isn't working inside getXML(). It sets the visible value in the field, but the original value gets sent with the submit. There are no policies set. Here's a synopsis of the code. Any help will be appreciated.
function onSubmit() {
var ga = new GlideAjax('...');
...
ga.getXML(
function (response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var stooges = JSON.parse(answer); // Okay
var payload = {
'stooge1' : stooges.moe,
'stooge2' : stooges.larry
};
var payload_string = JSON.stringify(payload); // Okay
g_form.clearValue('fieldname');
g_form.setValue('fieldname',payload_string); // Silent failure; original sent
}
);
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 07:06 AM
Thank you. I like getXMLAnswer() better. Unfortunately, g_form.submit() appears to reinvoke the onSubmit() handler putting it into an infinite loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 07:47 PM
I agree with @Medi C , getXML() is async so it won't wait for the script include response
try the script shared by @Medi C and share us the updates.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader