g_form.addInfoMessage and errorMessage does not work in Workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 04:06 AM - edited 11-27-2023 04:07 AM
Hi Team,
I have configured a client script which shows info message and error message on native UI and does not show in Workspace. Any Idea?
I was suspecting that as it is asynchronous call, it does not wait for the call to complete and it skips the getResponse() function.
Any Idea is appreciated.
@Ankur Bawiskar : Please share your valuable responses.
function onLoad() {
if (g_form.getDisplayBox('recovery_time_objective').value != '') {
var ga = new GlideAjax('sn_bia.BIAEngine'); //Scriptinclude
ga.addParam('sysparm_name', 'conflictRTO'); //Method
ga.addParam('bpSysid', g_form.getUniqueValue()); //Parameters
ga.addParam('bpRTO', g_form.getDisplayBox('recovery_time_objective').value);
ga.getXMLAnswer(getResponse);
}
function getResponse(response) {
var res = JSON.parse(response);
if (res > 1) {
g_form.addErrorMessage('You have ' + res + ' dependent Business Process having Higher RTO.');
g_form.showFieldMsg('recovery_time_objective', 'The Estimated RTO conflicts to its more than one dependent Business Process. Please review it before you create a plan.', 'error');
}
if (res == 1) {
g_form.addErrorMessage('You have one dependent Business Process having Higher RTO.');
g_form.showFieldMsg('recovery_time_objective', 'The Estimated RTO conflicts with one of its dependent Business Process. Please review it before you create a plan.', 'error');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 05:55 AM
Is the UI Type set to All? Is the script in the Global scope? Is Isolate script unchecked (just in case)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 05:58 AM - edited 11-27-2023 05:59 AM
Hi Brad,
Thanks for your response.
Yes.
UI Type - Set to "All"
Scope - "GRC: Business Impact Analysis"
Isolate Script - Set to "False"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 09:55 AM
Trying changing the Scope to Global, or create a new script as a test. I read somewhere that a certain client script only worked in Global for a workspace, but that could be unrelated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 11:21 AM
Hi @PrakashRam ,
The issue you're experiencing is likely due to the asynchronous nature of the GlideAjax call. The client script doesn't wait for the getResponse
function to finish before continuing with the rest of the code, which is why the error messages aren't displayed in the Workspace.
To address this, you can utilize GlideAjax's callback
property to ensure the error messages are displayed only after the asynchronous call completes. Here's the demo client script:
function onLoad() {
if (g_form.getDisplayBox('recovery_time_objective').value != '') {
var ga = new GlideAjax('sn_bia.BIAEngine'); // Scriptinclude
ga.addParam('sysparm_name', 'conflictRTO'); // Method
ga.addParam('bpSysid', g_form.getUniqueValue()); // Parameters
ga.addParam('bpRTO', g_form.getDisplayBox('recovery_time_objective').value);
ga.setCallback('getResponse'); // Set the callback function
ga.getXMLAnswer();
}
function getResponse(xml) {
var res = JSON.parse(xml.toString());
if (res > 1) {
g_form.addErrorMessage('You have ' + res + ' dependent Business Process having Higher RTO.');
g_form.showFieldMsg('recovery_time_objective', 'The Estimated RTO conflicts to its more than one dependent Business Process. Please review it before you create a plan.', 'error');
}
if (res == 1) {
g_form.addErrorMessage('You have one dependent Business Process having Higher RTO.');
g_form.showFieldMsg('recovery_time_objective', 'The Estimated RTO conflicts with one of its dependent Business Process. Please review it before you create a plan.', 'error');
}
}
}
getResponse
function will be called after the asynchronous GlideAjax call completes, ensuring that the error messages are displayed correctly in the Workspace.If you found this helpful, a 'like' is the secret handshake of appreciation! Accept it as a solution, as it will help others find the correct solution quickly.
- Prasad 😉