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-27-2025 12:18 PM
Hello @snowblind
Are you sending answer from script include in String format and it's Json ? Because then only parsing will work correctly .
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 12:25 PM
Yes. 'payload' is JSON. 'payload_string' is the stringified version of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 12:21 PM
@snowblind if you need only two values, why are you passing json at all ? Pass it in array and simply use [0] and [1] indexing. Or if whole Json is coming. And whole json is needed then directly use it , what's the need for parsing.
Too less of information is there, so there are many open ends to implement this.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 12:31 PM
My question has nothing to do with JSON. g_form.setValue() isn't setting the value regardless of type. I don't understand why it's still sending the original value.