I need to understand the condition in ui action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 10:08 AM - edited 02-09-2023 07:06 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 10:32 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 10:54 PM
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,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 11:43 PM
Hello @Community Alums
This is workspace form button.
You cannot see this UI action in the normal UI form.
So the condition works as:
- 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.
- ((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:
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 12:02 AM
Hi @SatyakiBose
Thanks for you help me to understand the i have one doubt .
- ((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