- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2019 09:54 AM
I have the below script that works properly, besides adding the info message.
I am thinking that the info message doesn't have time to run while the page is loading.
Would a setTimeout be a good option, or is there a better way to do this?
function getWarranties() {
//alert("You Clicked Me!");
var ga = new GlideAjax('MoxyiUtils');
ga.addParam('sysparm_name', 'getWarranty');
ga.addParam('sysparm_serial_number', g_form.getValue('serial_number'));
ga.getXML(handleResponse);
}
function handleResponse(response) {
var userAnswer = response.responseXML.documentElement.getAttribute('answer');
location.reload();
alertUser(userAnswer);
}
function alertUser(counter) {
g_form.addInfoMessage(counter + ' ' + 'Alert User Working');
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2019 11:01 AM
You can write an onDisplay Business Rule to query the contracts you added and display.
Though the message will be displayed everytime user opens the asset, it will still be useful.
The other option is to not reload, and show a message that Following contract has been added, please reload the form to see changes in contract tab. The contracts are anyway added in the background.
I am also wondering, why are you using a client script for this? Why not a business rule, which will load the form automatically after saving.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2019 10:14 AM
Hi,
Why to reload and then show message?
it won't work; once your reload the page then the page loads and next code won't work
try this; don't use reload
function getWarranties() {
//alert("You Clicked Me!");
var ga = new GlideAjax('MoxyiUtils');
ga.addParam('sysparm_name', 'getWarranty');
ga.addParam('sysparm_serial_number', g_form.getValue('serial_number'));
ga.getXML(handleResponse);
}
function handleResponse(response) {
var userAnswer = response.responseXML.documentElement.getAttribute('answer');
g_form.addInfoMessage(counter + ' ' + 'Alert User Working');
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2019 10:21 AM
I need the form to reload to reflect changes in the contract section of the hardware asset table. I then want to give the user confirmation of what just happened with an info message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2019 10:33 AM
Hi,
but in your script you are not setting any value etc then what is the purpose of the above script?
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2019 10:51 AM
I am adding contracts to the asset via a script include, then I want to pass back the number of contracts that were added to the client, refresh the hardware asset form, so the contracts actually show up under the asset, and then alert the user that everything was successful.
If i add the message before the reload, then it just disappears right away on the form reload.