Info message not getting displayed on Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 12:55 AM
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
});
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 01:07 AM
Hello @ujjwala_678 ,
Use the below format
gs.addMessage("info", "You have successfully approved the request.");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 01:36 AM
Hello @ujjwala_678
You are trying to fetch the data(data.InfoMessages) before it is initialized.
Try below server script:
(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.addInfoMessage("Policy record found");
gs.addInfoMessage("State: " + KnowledgeArticle.u_policy.state);
gs.addInfoMessage("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.";
}
}
}
data.InfoMessages = $sp.getWidget('display_info_message', {
MsgCondition: data.showMsg,
MsgValue: data.showMsgContent
});
gs.addInfoMessage(JSON.stringify(data.InfoMessages));
})();
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 01:48 AM
can you try this
HTML:
<div>
<div ng-if="data.showMsg" class="alert alert-info" style="margin-bottom: 20px;">
{{::data.showMsgContent}}
</div>
<p><strong>KB Article Sys ID:</strong> {{::data.sys_id}}</p>
<p><strong>Policy Type:</strong> {{::data.policyType}}</p>
<p><strong>Policy Owner:</strong> {{::data.policyOwner}}</p>
</div>
Server Side:
(function() {
data.sys_id = $sp.getParameter("sys_id");
data.showMsg = false;
data.showMsgContent = "";
var KnowledgeArticle = new GlideRecord('kb_knowledge');
if (KnowledgeArticle.get(data.sys_id)) {
var policyType = KnowledgeArticle.u_policy.type.getDisplayValue();
var policyOwner = KnowledgeArticle.u_policy.owner.getDisplayValue();
data.policyType = policyType;
data.policyOwner = policyOwner;
// Not retired or published, and published to udoc is true
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.";
}
}
// Retired and published to udoc is true
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.";
}
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 02:24 AM
Hello @Ankur Bawiskar ,
Thank you for your response earlier. With the provided code, I’m able to retrieve the sys_id of the KB article successfully. However, I'm currently unable to fetch the associated Policy Type and Policy Owner—these fields are returning empty.
Could you please help me understand what might be causing this? If there's something I might be overlooking in terms of field access, relationship, or dot-walking, I’d really appreciate your guidance.
Thank you