I need to understand the condition in ui action?

Community Alums
Not applicable

Hi, 

I need to understand how the condition in ui action and the if condition in the script will work. Can anyone help me to understand the how its work. 

Condition:  newGlideRecord("incident").canCreate() && ((current.isNewRecord() && current.canCreate()) || !current.isNewRecord())

 

Script: 

var canCreateIncident = false;

if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite()))
canCreateIncident = current.update();
else
canCreateIncident = true;

if (canCreateIncident) {
var inc = new GlideRecord("incident");

inc.short_description = current.short_description;
inc.description = current.u_description;

}

Thanks 

 

 

10 REPLIES 10

Hi @Community Alums 

For an existing record there should be an incident linked already if it has been created.

Therefore no validation is done for existing record to create incident.

The interpretation of that condition is: show the UI Action if either of these two conditions are met:

- the current record is a new record and the (current) user has create rights (current.isNewRecord() && current.canCreate()) or

- the current record is not a new record (!current.isNewRecord()).

Community Alums
Not applicable

Hi @-O- 

 

Thanks for i understood now.

do you know when the if will get pass for this script and if the UI action scoped is changed  from ITSM Workspace now it changed to global what will be the impact

Script: 

var canCreateIncident = false;

if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite()))
canCreateIncident = current.update();
else
canCreateIncident = true;

if (canCreateIncident) {
var inc = new GlideRecord("incident");

inc.short_description = current.short_description;
inc.description = current.u_description;

}

Thanks,

Changing the script to global scope, given that Incident is in global scope is not a problem. However without knowing where this script runs, without knowing what current is, I can't say much about the script.

Community Alums
Not applicable

Hi @-O- ,

Thanks for the reply

This script Create Incident UI action in Interaction table in AWS.

can you help me to understand when the if condition will get pass.(line no: 6 if condition when it will get pass)

I have attached the screenshot of the UI action.

Thanks