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-10-2023 12:21 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 01:20 AM
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()).

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 08:10 AM
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