Need to show Alert or Error Message in onCellEdit client script

Indup
Tera Expert

HI All,

I have written a on CellEdit client script on incident table, when ever close notes is empty and close code is none, then it should not allow to closed the incident from the list view even. It is preventing incident closure but how to show an error message or alert to the user on the scrren.

My code:

Table: Incident

Field:State

Script:

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
var closeCode = g_form.getValue('close_code');
var closeNotes = g_form.getValue('close_notes');


if(closeCode == none || closeNotes == '' && oldValue != 3 && newValue == 3)

{
alert("Close the notes and code first");
saveAndClose = false;
}
else
{

saveAndClose = true;
}

callback(saveAndClose);
}

I am not able to see the Alert message

Can some one correct my code plz

 

 

Regards,

Indup

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Indup,

I don't think you can access g_form operations from the list view. I would recommend switching to Before business rule to handle the validation and to abort the action. 

 

- Pradeep Sharma

View solution in original post

7 REPLIES 7

HI Pradeep,

I have written Before BR on Update, 

When to Run:

before : update

state changes to Closed

 

Script:

if(current.close_notes == '' || current.close_code == none)
{
gs.addInfoMessage("Close Notes and CLose Code need not be empty before Closure");
}

 

But even now it is not showing info message on incident list

 

Regards

Indup

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Updated script below.

if(current.close_notes == '' || current.close_code == '')
{
gs.addInfoMessage("Close Notes and CLose Code need not be empty before Closure");
}

Harsh Vardhan
Giga Patron

g_form works on the form. 

it will not work in the list . you can switch it to before business rule and add the filter condition 

and then in action tab set the message .