- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 08:39 AM
I am trying to create a portal pop-up window (modal) that displays when a user accesses a CLOSED task record in portal (incident, request item, change, etc.). This modal should instruct the user that the record they are accessing is closed and provide them with instructions on what to do next.
I am unable to craft the proper onLoad client script to trigger the modal. I am wondering if anyone else has something similar they could share...
Thanks
Solved! Go to Solution.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2020 01:46 PM
Here you go. This is tested an working on an INC record.
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var id = '';
if(input.action === 'checkRec'){
id = $sp.getParameter('sys_id');
}
data.active_record = isRecordActive(id);
function isRecordActive(sysID){
var active = '';
var task = new GlideRecord('task');
task.get(sysID);
active = task.active;
return active.toString();
}
})();
Client Script:
function(spModal) {
/* widget controller */
var c = this;
var activeRecord = '';
c.server.get({
action: 'checkRec'
}).then(function(response){
activeRecord = response.data.active_record;
if(activeRecord == 'false'){
spModal.open({
title: 'This is a test title for false record',
message: 'This is a test message.',
buttons: [{label:'OK', primary:true}]
});
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2020 12:12 PM
Might need to tweak this. Give me a bit. I'm close.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2020 01:46 PM
Here you go. This is tested an working on an INC record.
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var id = '';
if(input.action === 'checkRec'){
id = $sp.getParameter('sys_id');
}
data.active_record = isRecordActive(id);
function isRecordActive(sysID){
var active = '';
var task = new GlideRecord('task');
task.get(sysID);
active = task.active;
return active.toString();
}
})();
Client Script:
function(spModal) {
/* widget controller */
var c = this;
var activeRecord = '';
c.server.get({
action: 'checkRec'
}).then(function(response){
activeRecord = response.data.active_record;
if(activeRecord == 'false'){
spModal.open({
title: 'This is a test title for false record',
message: 'This is a test message.',
buttons: [{label:'OK', primary:true}]
});
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2021 12:17 PM
Hi John,
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
//data.isNotPublished = false;
//gs.log("JMC Modal sysid: " + article_sysid);
var id;
if(input.action === 'checkRec'){
id = $sp.getParameter('sys_kb_id');
}
data.status;
function isNotPublished(article_sysid){
//Check if the article state is Draft or Retired
var gkb = new GlideRecord('kb_knowledge');
gkb.addQuery('sys_id',article_sysid);
gkb.query();
{
data.status = gkb.workflow_state;
//gs.log("JMC Modal record found! " + article_sysid);
if(gkb.workflow_state != 'published')
{
return true;
}
else
return false;
}
}
gs.log("JMC Modal isDraftOrRetired: " + data.isNotPublished + ", workflow state: " + data.status);
})();
/* widget controller */
var c = this;
var status;
action: 'checkRec'
}).then(function(response)
{
isNotPublished = response.data.isNotPublished;
status = response.data.status;
if(isNotPublished){
// spModal.open({
// message: 'This is a test message.',
// buttons: []
// });
spModal.confirm("This article is in " + c.data.status + " status."
);
}
});
I was also trying to dynamically display the status of the article on the confirmation itself, is that possible?
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2021 09:55 PM
You were really close. You are getting a blank modal because you don't need both spModal.open and spModal.confirm just one or the other. API docs has good examples here, https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/SPModal-API , but I also included example below. I changed around some of the vars and what not but I hope this helps. It is possible to dynamically display the KB state, also tested this in Rome in a personal dev and is working. I included a redirect example to bring the user back to kb_home I'm just not sure where you want to navigate them or why someone would be clicking on a retired article but it should be possible using any client side redirect. You can also concatenate a url somehow if that's what you are looking for.
SERVER
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
//var article_sysid = $sp.getParameter('sys_kb_id');
//data.isNotPublished = false;
//gs.log("JMC Modal sysid: " + article_sysid);
var id;
//if(!input && input.action === 'checkRec'){
id = $sp.getParameter('sys_id');
//}
data.workflowState = workflowState(id);
data.published = true;
if(data.workflowState != 'Published'){
data.published = false;
}
function workflowState(article_sysid){
var arr = [];
//Check if the article state is Draft or Retired
var gkb = new GlideRecord('kb_knowledge');
gkb.addQuery('sys_id',article_sysid);
gkb.query();
if(gkb.next())
{
return gkb.workflow_state.getDisplayValue();
//gs.log("JMC Modal record found! " + article_sysid);
}
}
gs.info("JMC Modal State: " + data.workflowState + ", Published? " + data.published);
})();
CLIENT
function(spModal, $location) {
/* widget controller */
var c = this;
c.confirmed = "asking";
var warn = '<i class="fa fa-warning" aria-hidden="true"></i>';
spModal.open({
title: 'Knowledge Article',
message: warn + ' This article is in ' + c.data.workflowState + ' status.'
}).then(function(confirmed) {
c.confirmed = confirmed;
$location.search('id=kb_home')
})
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2021 10:59 AM
Thank you, John! Will try this out!