Info message not getting displayed on Portal

ujjwala_678
Tera Contributor

Hi everyone,

I’m facing an issue where info messages pushed from a widget or script are not getting displayed on the Service Portal. I'm using g_form.addInfoMessage() and also tried gs.addInfoMessage() within server scripts, but nothing shows up on the portal UI. I am getting sys_id of kb article but not other type of data which I am trying to receive.
However, the same logic works fine on the standard platform UI (forms).

Has anyone encountered this before?

Things I’ve tried so far:

  • Confirmed that the widget is rendering properly.

  • Verified that the message is being triggered (checked logs).

  • Checked if any client script or CSS might be hiding the message.

  • Tested with different user roles and permissions.

Would appreciate any suggestions or pointers on:

  • Why the info message might not be rendering on the portal.

  • If there’s a specific way to surface messages in widgets.

  • Any required configuration or alternative method to show messages on the portal.

Thanks in advance for your help!

HTML:
<sp-widget widget=data.InfoMessages> </sp-widget>
<p>{{::c.data.sys_id}}</p>
<p><strong>Policy Type:</strong> {{::c.data.policyType}}</p>
<p><strong>Policy Owner:</strong> {{::c.data.policyOwner}}</p>
client side:
api.controller=function() {
  /* widget controller */
  var c = this;
};
Server side:
(function() {
    /* populate the 'data' object */
    /* e.g., data.table = $sp.getValue('table'); */

    //Pass parameters- MsgCondition: when to display info message and MsgValue: what to display in info message below
    data.showMsg = true;
    data.sys_id =  $sp.getParameter("sys_id");

    var KnowledgeArticle = new GlideRecord('kb_knowledge');
   if (KnowledgeArticle.get(data.sys_id)) {
  gs.info("Policy record found");
  gs.info("State: " + KnowledgeArticle.u_policy.state);
  gs.info("u_publish_to_udoc: " + KnowledgeArticle.u_publish_to_udoc);
 

        var policyType = KnowledgeArticle.u_policy.type.getDisplayValue();
        var policyowner = KnowledgeArticle.u_policy.owner.getDisplayValue();
		 data.policyType = policyType;
     data.policyOwner = policyowner;



        if (KnowledgeArticle.u_policy.state != 'retired' && KnowledgeArticle.u_policy.state != 'published' && KnowledgeArticle.u_policy && KnowledgeArticle.u_publish_to_udoc == 'true') {
            data.showMsg = true;

            if (policyType == "Policy") {
                data.showMsgContent = "This " + policyType + " is currently going through a document refresh. Please note that some of this content may change soon as a result.";
            } else {
                data.showMsgContent = "This " + policyType + " policy is currently going through a document refresh. Please note that some of this content may change soon as a result.";
            }
        }

        if ((KnowledgeArticle.u_policy.state == 'retired')&&(KnowledgeArticle.u_publish_to_udoc == '1')) {
            data.showMsg = true;

            if (policyType == "Policy") {
                data.showMsgContent = "This " + policyType + " has expired or has been retired and is no longer valid. Please contact the policy owner " + policyowner + " for more information.";
            } else {
                data.showMsgContent = "This " + policyType + " policy has expired or has been retired and is no longer valid. Please contact the policy owner " + policyowner + " for more information.";
            }
        }
		//published to udoc is false
		if (KnowledgeArticle.u_publish_to_udoc == '0') {
            data.showMsg = true;

            if (policyType == "Policy") {
                data.showMsgContent = "This " + policyType + " hasn't been published to uDOC. Please contact the policy owner " + policyowner + " for more information.";
            } else {
                data.showMsgContent = "This " + policyType + " policy hasn't been published to uDOC. Please contact the policy owner " + policyowner + " for more information.";
            }
        }

    }
	gs.info(JSON.stringify(data.InfoMessages));


    data.InfoMessages = $sp.getWidget('display_info_message', {
        MsgCondition: data.showMsg,
        MsgValue: data.showMsgContent
    });

})();

 

8 REPLIES 8

@ujjwala_678 

are you sure the field names are correct?

If you are able to get sysId then the field values you should get as well.

Did you try running the script in background and see what value those fields hold by passing hard-coded sysId?

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes, the field names are correct. I also tried running the script in the background and was able to retrieve the data successfully through log messages. However, I noticed that the widget is part of the Knowledge Management - Service Portal scope. Could this scoping be the reason why the policy fields like Policy Owner and Policy Type are not getting fetched on the portal? Would appreciate your thoughts on this.

@ujjwala_678 

those are custom fields? but in which scope?

try this and use other way for getting the field value and once you get sysId then query the table again to get display value

var policyType = KnowledgeArticle.u_policy.type;
        var policyowner = KnowledgeArticle.u_policy.owner;

// query the type table and sys_user table if owner refers to sys_user

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Anil Nemmikanti
Giga Guru

Hi @ujjwala_678 ,

please use spUtil.addInfomessage() method in portal instead of g_form.addInfomessage().