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

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Nothing wrong with the script & use of alert. Can you make sure pop-up blocker or not pop-up is not configured for your browser. Alternatively, check in different browser as well.

 

Thanks,

Jaspal Singh

HI Jaspal,

I tested in mozilla and chrome as well. But alert is not showing. But it is preventing incident closure. I need alert message. SO what is wrong here

 

Regards,

Indup

In that case as Pradeep suggested, better switch to Business rule that runs before update & aborts actions if fields are missing with required set of Error messages using gs.addErrorMessage().

 

Thanks,

Jaspal Singh

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