g_form.setValue() fails inside getXML()

snowblind
Tera Expert

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;
}

 

11 REPLIES 11

Thank you.  I like getXMLAnswer() better.  Unfortunately, g_form.submit() appears to reinvoke the onSubmit() handler putting it into an infinite loop.

Ankur Bawiskar
Tera Patron
Tera Patron

@snowblind 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader