In servicenow i want that ui action button only visible to the assigned to user of incident.
Assistant
In ServiceNow, you can control the visibility of a UI Action button based on specific conditions using a Condition Script. To make a UI Action button visible only to the user assigned to an incident, you will need to add a condition script to the UI Action record.
User
I have a custom ui action on incident tabel
Assistant
If you have a custom UI Action on the Incident table and you want it to be visible only to the user assigned to the incident, you can follow these steps to add a condition script to control its visibility.
Navigate to the UI Action record:
Go to All > System UI > UI Actions.
Locate the UI Action you want to conditionally display.
Modify the Condition:
Open the UI Action record.
In the "Condition" field, you'll need to add a script that checks if the current user is the same as the user in the "Assigned to" field of the Incident.
Here is an example of a condition script you can use:
current.assigned_to == gs.getUserID();
This script compares the assigned_to field on the current record (current.assigned_to) with the ID of the currently logged-in user (gs.getUserID()). The button will only be visible if these IDs match.
Save the UI Action:
After adding the condition script, click the Update button to save the changes.
Example:
Suppose you have a UI Action named "Resolve Incident." You want this button to be visible only to the user assigned to the incident.
Here's how you can set it up:
Locate the UI Action:
Go to All > System UI > UI Actions.
Search for "Resolve Incident" and open the corresponding UI Action record.
Set the Condition:
In the "Condition" field, enter the following script:
current.assigned_to == gs.getUserID();
Save the Record:
After entering the condition, click Update.
Now, the "Resolve Incident" button should only be visible to the user who is listed in the "Assigned to" field of the incident record.
Important Considerations:
Ensure that the field assigned_to is not empty when testing this; otherwise, the condition will fail.
This condition assumes the user has an active session and is properly logged in.
Make sure other conditions required for the UI Action are accounted for as well (e.g., the incident state).
If you need further customization or more complex conditions, you can extend the script to handle additional logic.
Steps:
Navigate to the UI Action:
Go to All > System UI > UI Actions.
Locate your custom UI Action by filtering on the Table column for "incident".
Edit the Condition:
Open the UI Action record.
In the "Condition" field, you will need to add a script that ensures the button is only visible to the user assigned to the incident.
Example Condition Script:
In the "Condition" field of the UI Action, you can use the following script to check if the current user is the assigned to user of the incident:
current.assigned_to == gs.getUserID();
Full Example
Let's go through a specific example:
Navigate to your custom UI Action:
Go to All > System UI > UI Actions.
Filter the "Table" column by "Incident" to find your custom UI Action.
Open and Edit the UI Action:
Open your custom UI Action.
Locate the "Condition" field. This is where you will add the condition to check if the current user is the one assigned to the incident.
Add the Condition Script:
In the "Condition" field, add the following JavaScript code:
current.assigned_to == gs.getUserID();
Save the UI Action:
Click Update to save the changes.
Explanation:
current.assigned_to retrieves the assigned_to value of the current incident record.
gs.getUserID() retrieves the user ID of the currently logged-in user.
By comparing these two values, the UI Action will only be visible to the user who is assigned to the incident.
Additional Considerations:
Empty assigned_to Field: Ensure that the assigned_to field is not empty when testing this, as the button will not appear if assigned_to is empty.
UI Action Scope: Make sure your custom UI Action is configured correctly and appears on the form where you expect it to.
User Roles: Keep in mind that other conditions or user roles might affect the visibility or functionality of the UI Action. Ensure no other scripts or conditions are overriding your intended behavior.
By following these steps, your custom UI Action on the Incident table will be visible only to the user who is assigned to the incident.