GetXMLWait() vs GetXML()

Johannes Mweli
Giga Guru

Hi ServiceNow Community Developers,

 

I keep hearing that GetXML() is good to use, best practice and recommended over GetXMLWait(). However I am wondering what do you do in a case where you need to wait for a response to come back in your script before you proceed.  Can you achieve that behavior with GetXML()? If so, how?

 

For instance,  let’s say you need to do a server side lookup before you submit your form. The submission depends on the value that will be returned by an AJAX call. If I use GetXML() my form always gets submitted before the response comes back and that is the behavior that I don’t want. On the other hand if I use GETXMLWait() I get the correct behavior because the client waits until the value that I need to check for before submitting the form is returned.

 

Basically what I am trying to figure out is if we are advised to use GetXML() instead of GetXMLWait() how do we then achieve the functionality that GetXMLWait() has especially where you need the value from server to use for processing downstream in your script.

 

I also read somewhere that GetXMLWait() is no longer supported however I am wondering for the life of me how does one then use GetXML() and get the same functionality like the one GetXMLWait() has.

 

Kindly advise please.

 

Thanks,

Johannes

1 ACCEPTED SOLUTION

Rohit  Singh
Mega Sage

Hi @Johannes Mweli ,

 

It's not like geXML() is recommended over getXMLWait(). Both work differently one is asycnchronous and other is synchronous. You can't use getXML() in a synchronous way hence use getXMLWait() only. It all depends upon the use case.

 

If my response helped, please mark it helpful and accept the solution so that it benefits future readers.

 

Regards,
Rohit

View solution in original post

3 REPLIES 3

Rohit  Singh
Mega Sage

Hi @Johannes Mweli ,

 

It's not like geXML() is recommended over getXMLWait(). Both work differently one is asycnchronous and other is synchronous. You can't use getXML() in a synchronous way hence use getXMLWait() only. It all depends upon the use case.

 

If my response helped, please mark it helpful and accept the solution so that it benefits future readers.

 

Regards,
Rohit

Johannes Mweli
Giga Guru

@Rohit Singh  - this is exactly what I thought but wanted to confirm with the community

@Johannes Mweli Glad I was able to help. Please mark my solution as helpful as well.

 

Regards,

Rohit