g_form.addInfoMessage and errorMessage does not work in Workspace

PrakashRam
Tera Contributor

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

 

 

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Is the UI Type set to All?  Is the script in the Global scope?  Is Isolate script unchecked (just in case)?

Hi Brad,

 

Thanks for your response.

 

Yes. 

UI Type           -    Set to "All"

Scope              -    "GRC: Business Impact Analysis"

Isolate Script  -   Set to "False"

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.

Community Alums
Not applicable

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