message shouldnt come in cab workbench

ServiceNow10sun
Giga Guru

I wan to restrict message in cab workbench page , however i am not getting  message anywhere not in classic UI not in SOW  not in cab workbench , however i need message in classic UI and in SOW .

 

function onLoad() {
    var state = g_form.getValue("state");

    var url = window.location.href;
    var path = window.location.pathname;

    var isCABWorkbench = (url.indexOf("cab_workbench") !== -1) || (path === "/cab");

    // Stop only for CAB Workbench
    if (isCABWorkbench) {
        return;
    }

    if (state === "-5" || g_form.isNewRecord()){
    g_form.addinfomessage("Hi");
    }
}
4 REPLIES 4

pr8172510
Mega Guru

Hi ServiceNow10sun,

Why your message is not showing anywhere

The issue is in your script:

g_from.addinfomessage("Hi");

 

Typo:

  • g_from 
  • Should be → g_form 

Because of this:

  • Script is failing silently
  • Message is not displayed in Classic UI, SOW, or CAB

i have corrected but still its not working 

pr8172510
Mega Guru
  • g_form.addInfoMessage()
     Works in Classic UI
    Not reliable in Workspace (SOW / CAB Workbench)

That’s why you’re not seeing the message.



function onLoad() {

// Skip Workspace (SOW + CAB)
if (typeof NOW !== 'undefined') {
return;
}

var state = g_form.getValue("state");

if (state === "-5" || g_form.isNewRecord()) {
g_form.addInfoMessage("Hi");
}
}

Tanushree Maiti
Kilo Patron

1. Ensure the Client Script has UI Type set to All

 

Try with this code. If any error is throwing from your current code, please share that.

 

function onLoad() {
    var state = g_form.getValue("state");

 

    var url = window.location.href;
   // var path = window.location.pathname;

 

  if (url.indexOf('cab_workbench') > -1) {
return;
}

 

    if (state == "-5" || g_form.isNewRecord()){
    g_form.addinfomessage("Hi");
    }
}

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: