Need help with OnLoad modal in portal

john_duchock
Kilo Guru

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

 

1 ACCEPTED SOLUTION

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

}

 

View solution in original post

11 REPLIES 11

John Longhitano
Kilo Guru

Hi John,

 

What page or widget are you trying to display this popup on?  There's a few ideas I have that could work.

john_duchock
Kilo Guru

I was going to create my own widget...  it is a simple confirm() widget with simple text:   "Closed records cannot be updated".  User clicks "OK" and can proceed to view the record.

This would open on the "ticket" page in portal and only be presented if the record is closed (data.state = x)

This way, if a user opens (onLoad) a closed record (from an old email link or something), they would immediately be told that they cannot update the record.

I'll get back to you soon.  I have an idea but we may have to clone one of the OOB widgets.  Going to test it first.

Ok so try this out we can do this without cloning anything.  Create a new widget and add that widget anywhere on the 'ticket' page.  Copy and paste the code below.  I think the example will help you create your solution.

 

Widget Server Script:

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */


data.sys_id = $sp.getParameter('sys_id');
data.active = isRecordActive(data.sys_id);

function isRecordActive(sysID){
var task = new GlideRecord('task');
task.get(sysID);
return task.active;
}
})();

Widget Client Script:

function(spModal) {
/* widget controller */
var c = this;
c.active = c.data.active;

if(c.active){
spModal.open({
title: 'This is a test title for active record',
message: 'This is a test message.',
buttons: [{label:'OK', primary:true}]
});
}

if(!c.active){
spModal.open({
title: 'This is a test title for false record',
message: 'This is a test message.',
buttons: [{label:'OK', primary:true}]
});
}

}