in servicenow, i didnt have add to update set related link utility in my personal developer instance, i want to create a custom ui action that shows add to update set related link in the group form all the time after it gets created
Assistant
User
please provide me the script so that user click on it and the current record gets captured in current update set of logged in user
Assistant
User
set redirect url true also
Assistant
To create a custom UI Action in ServiceNow that always displays the "Add to Update Set" related link on a group form after it gets created, you can follow these steps:
Step 1: Create the Custom UI Action
Navigate to UI Actions:
Go to the ServiceNow application navigator and type UI Actions.
Click on the UI Actions module under System Definition.
Create a New UI Action:
Click on the "New" button to create a new UI Action.
Fill in the Fields:
Name: Give your UI Action a descriptive name (e.g., Add to Update Set Link).
Table: Select the table where you want this action to appear (for groups, it would typically be sys_user_group).
Active: Make sure this checkbox is checked.
Position: Set this based on where you want the action to appear in the UI. You can adjust it according to your needs.
Show Insert: Check this box to show this UI Action when inserting a new record.
Show Update: Check this box to show this UI Action when updating an existing record.
Condition: You can select a condition to limit when the UI Action is displayed. If you want it to display every time, you can leave this blank or set it as true.
Script: In this field, you can write the script to include the functionality to add this to the update set. For example:
javascript
// This script runs when the UI Action is called
// Here you can integrate with existing functions or custom methods
// if you want any specific functionality to execute when clicked.
gs.addInfoMessage('Added to Update Set!'); // Just a placeholder message
return true; // returning true for successful execution
Step 2: Call the Update Set Functionality
If you want to specifically implement the functionality to add the current record to the update set, you may need to interact with the update set APIs within ServiceNow. However, that behavior is usually handled by the platform itself for default records when they are modified and saved.
Step 3: Test Your UI Action
Testing:
Create a new group record to see if the "Add to Update Set" link appears as expected.
Confirm that clicking it either shows a message or performs the expected behavior.
Step 4: Adjust and Refine
You can refine the conditions, styles, and scripts for better functionality depending on your specific needs.
Ensure your UI Action complies with existing business rules and fits well within the overall user experience of your instance.
Important Notes:
Always ensure you are following best practices and testing in a development instance before deploying changes to production.
If you want to customize system behavior significantly or handle the update set manually, more advanced scripting may be required, along with permissions for the user who will be performing these actions.
By following the above steps, you should be able to create a custom UI action that provides the capability to add to update set functionality within the group form efficiently.
To create a custom UI Action in ServiceNow that allows users to manually add the current record to the current user's update set upon clicking a button, you'll need to write a script that captures this action. The script interacts with the Update Set feature of ServiceNow.
Here is a sample script you can use for your UI Action:
Step-by-Step Instructions to Create the UI Action
Navigate to UI Actions:
In the application navigator, type UI Actions and click on it.
Create a New UI Action:
Click on the "New" button.
Fill in the Fields:
Name: Add to Current Update Set
Table: sys_user_group (or your desired table).
Active: Checked
Show Insert: Checked
Show Update: Checked
Position: Choose where you want this UI Action to appear on the form (usually set a lower number for top).
Condition: You can use this condition if you want: current.update_set != '' (this makes sure the current record is only added if it's in an update set).
Script: Insert the following script in the Script field:
javascript
// Server-side script to add the current record to the update set
var updateSet = new GlideRecord('sys_update_set');
updateSet.get(current.update_set);
var currentRecord = current.sys_id;
// Create a new Update Set Entry
var updateSetEntry = new GlideRecord('sys_update_set_entry');
updateSetEntry.initialize();
// Set the related fields
updateSetEntry.name = current.getDisplayValue(); // or any display name you want
updateSetEntry.operation = 'insert'; // or 'update' based on your record
updateSetEntry.document_id = currentRecord;
updateSetEntry.update_set = current.update_set;
// Insert the record
var entrySysId = updateSetEntry.insert();
// Verify entry was created and provide feedback to the user
if (entrySysId) {
gs.addInfoMessage('Current record has been added to the update set.');
} else {
gs.addErrorMessage('Failed to add the record to the update set.');
}
return; // Ensure the process completes gracefully
Important Considerations
Condition: The condition you set (like checking if the current.update_set is not empty) controls when the button appears to the user.
Permissions: Make sure that the user roles have the necessary permissions to execute this UI Action. Users need permissions to write to the sys_update_set and sys_update_set_entry tables.
Testing: After creating the UI Action, test it in a development instance to ensure it works correctly and adds the record to the appropriate update set.
Avoid Conflicts: Be careful about workflows or business rules that might interfere with this action.
Once you've added this UI Action with the provided script, it should give users the ability to add the current record to their update set upon clicking it.
If you would like to set redirect to true after adding the record to the current update set, you can modify the UI Action's script slightly to include a redirect to the same record or provide any other URL you want to redirect the user to after the action is completed.
Updated Script for Redirect
Here's how you can incorporate redirect into the UI Action's script:
Navigate to UI Actions:
In the application navigator, type UI Actions and click on it.
Create a New UI Action (or edit existing):
For a new UI Action, use the following parameters.
If editing, replace the script part with the new code below.
Script: Use the following script in the Script field:
javascript
// Server-side script to add the current record to the update set
var updateSet = new GlideRecord('sys_update_set');
if (updateSet.get(current.update_set)) {
var currentRecord = current.sys_id;
// Create a new Update Set Entry
var updateSetEntry = new GlideRecord('sys_update_set_entry');
updateSetEntry.initialize();
// Set the related fields
updateSetEntry.name = current.getDisplayValue(); // or any display name you want
updateSetEntry.operation = 'insert'; // or 'update' based on your record
updateSetEntry.document_id = currentRecord;
updateSetEntry.update_set = current.update_set;
// Insert the record
var entrySysId = updateSetEntry.insert();
// Verify entry was created and provide feedback to the user
if (entrySysId) {
gs.addInfoMessage('Current record has been added to the update set.');
} else {
gs.addErrorMessage('Failed to add the record to the update set.');
}
}
// Redirect to the current record
action.setRedirectURL(current);
return; // Ensure the process completes gracefully
Explanation of Redirect
The line action.setRedirectURL(current); is what triggers the redirect to the current record. This will take the user back to the record they were working with after executing the action.
The return; statement ensures that the UI Action completes correctly.
Summary
Place the modified script in the Script field of your UI Action.
Ensure the conditions are as necessary for your use case.
Test the action to make sure it behaves as expected, both in terms of adding to the update set and redirecting back to the record.
With these modifications, users will see a success or error message after clicking the UI Action, and they will automatically be redirected back to the current record, enhancing the usability of the feature.