How to prevent a form from being submitted in an onsubmit client script with a getXML() function?

Johannes Mweli
Giga Guru

Hi ServiceNow Community Developers

 

I have the following use case: I am in a scoped application. I am using the onsubmit client script that has the getXML() function. There are fields on the form that I am submitting that needs to be populated by the response of the getXML() function before the form can be submitted. The issue I am running into though is that since getXML() is async it does not wait for the response to come back from the server, it issues a call to the server and then goes ahead and submit the form before the response comes back. As a result of this behavior some fields are submitted without getting populated.

 

Would you guys please advise if there is a way I can overcome this. In other words is there a way to pause the form submission until the fields that needs to populated by the response  from getXML() function have been populated.

 

Kindly advise please

 

Thanks,

Johannes

1 ACCEPTED SOLUTION

@Johannes Mweli  SN has created a support article explaining this and how to make async call in onsubmit

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579 

 

NOTE: This does not work in catalog client script, as per my discussion with HI support.


Raghav
MVP 2023

View solution in original post

5 REPLIES 5

Sourabh Tarlekr
Kilo Sage

Hi @Johannes Mweli 

 

You can use getXMLWait() so that all fields get populated from the server. If you still want to use getXML() then you can put a condition that if required fields that needed to be populated form server if empty then use 'return false' to prevent the form submission.

 

Regards,

Sourabh

Hi Sourabh,

 

getXMLWait() does not work in a scoped application, that's why I am using getXML().

 

Thanks,

Johannes

@Johannes Mweli  SN has created a support article explaining this and how to make async call in onsubmit

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579 

 

NOTE: This does not work in catalog client script, as per my discussion with HI support.


Raghav
MVP 2023

Hi @RaghavSh 

 

That works! thank you so much for your help on this question.

 

Johannes