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

SatyakiBose
Mega Sage

Hello @Community Alums 

Can you please elaborate what this UI action is supposed to do.

Do you have an XML of the UI action that you can attach here, and explain what exactly are we looking for.

Community Alums
Not applicable

Hi @SatyakiBose ,

I am referring the Create incident UI action in interaction form that is OOB UI action i am not able to understand the condition and the how the if condition works in the script can you help me to understand as i am fresh to servicenow.

Thanks,

 

 

Hello @Community Alums 

This is workspace form button.

You cannot see this UI action in the normal UI form.

So the condition works as:

  1. new GlideRecord("incident").canCreate() --> The condition first checks if the user has access to incident table, and also has access to create a new record in the incident table.
  2. ((current.isNewRecord() && current.canCreate()) || !current.isNewRecord()) --> Now the system checks if the interaction is new record or not, and does the current user has got access to create a new incident. Also, it checks if this is an existing record, and the user has got access to create an incident.

If both of these conditions are satisfied, the user will be able to see the UI action on the workspace form.

 

Now coming to the script:

  1. if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite())) --> If the incident is a new record, and the user and create, or if its an existing interaction, and the user can edit, then it updates the incident.

Hope this clears your dount.

Community Alums
Not applicable

Hi @SatyakiBose 

 

Thanks for you help me to understand the i have one doubt .

 

  1. ((current.isNewRecord() && current.canCreate()) || !current.isNewRecord()) -->it checks if this is an existing record, and the user has got access to create an incident.

for existing record it will check the user is having create to the incident ? 

Thanks