Copy UI Policy actions to another UI Policy?

bigbacon
Giga Guru

Is it possible to copy UI policy actions to another UI Policy?

 

I have a situation where the UI policies I have are fairly complex and the UI policies are against the same items but I just need to change visiblity/etc. and having to manually recreate like 15 items per action is a total pain.

1 ACCEPTED SOLUTION

bigbacon
Giga Guru

so, the real solution is you can't....

View solution in original post

11 REPLIES 11

explain?

@bigbacon Open the UI Policy that you want to copy the UI Policy Actions from. Click on the hamburger menu and then select Insert with Actions. This will create a duplicate of your UI Policy record, and will also copy over the UI Policy Actions, and then you can modify the new record to meet your needs.

 

My screenshot shows this with a Catalog UI Policy, but it works with regular UI Policies too.

jc21_0-1736795210014.png

 

Works! Thank you!

MackI
Kilo Sage

hi @bigbacon 

 

Yes, it is possible to copy UI Policy Actions from one UI Policy to another in ServiceNow, but there's no built-in button or feature in the UI to do it directly. You'll need to use a couple of different methods to achieve this:

Methods to Copy UI Policy Actions

1. Using Background Scripts (Most Efficient for Bulk Copying)

This method is best if you have many UI Policy Actions to copy or need to repeat this process multiple times.

 

(function copyUIPolicyActions() {

    var sourceUIPolicySysId = 'YOUR_SOURCE_UI_POLICY_SYS_ID'; // Replace with the sys_id of your source UI Policy
    var targetUIPolicySysId = 'YOUR_TARGET_UI_POLICY_SYS_ID'; // Replace with the sys_id of your target UI Policy

    // Get the source UI Policy Actions
    var sourceActions = new GlideRecord('sys_ui_policy_action');
    sourceActions.addQuery('ui_policy', sourceUIPolicySysId);
    sourceActions.orderBy('order'); // Maintain the original order
    sourceActions.query();

    while (sourceActions.next()) {
        // Create a new UI Policy Action for the target UI Policy
        var targetAction = new GlideRecord('sys_ui_policy_action');
        targetAction.initialize();

        // Copy relevant fields (adjust as needed based on your requirements)
        targetAction.ui_policy = targetUIPolicySysId;
        targetAction.field_name = sourceActions.field_name;
        targetAction.clears_value = sourceActions.clears_value;
        targetAction.mandatory = sourceActions.mandatory;
        targetAction.visible = sourceActions.visible;
        targetAction.read_only = sourceActions.read_only;
        targetAction.order = sourceActions.order;
        targetAction.script_false = sourceActions.script_false; //if copying the script
        targetAction.script_true = sourceActions.script_true; //if copying the script

        // Insert the new action
        targetAction.insert();
    }

    gs.print('UI Policy Actions copied successfully!');

})();
 
Case: Another Production Instance 
Data Replication (Recomended) [Make sure your company have ITSM Pro or above version] 
If your company has two production instance for a subsidiary company or other sub-entity 
 
Team Development Application: You must have the Team Development application (com.snc.sdlc.teamdev) installed and activated on your instances.
 
You need to setup parent and child hierarchy,contact your system Admin for this Data Replication

 

If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer‌🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community

MackI | ServiceNow Technical Consultant | DXC Technology Australia | ServiceNow Practice | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia

hi @bigbacon 

 

If you are feel uncomfortable with script then the other strategy Action &Stay 

 

Manual Copying with "Insert and Stay" (For a Few Actions)

If you only have a few UI Policy Actions to copy, you can do it manually using the "Insert and Stay" functionality:

Open the Source UI Policy: Go to the UI Policy record from which you want to copy actions.
Open the UI Policy Actions List: In the "UI Policy Actions" related list, right-click the header and choose "Open in New Window".
Open the Target UI Policy: Open the target UI Policy where you want to add the copied actions.
Go to the Source UI Policy Actions List: In the newly opened window, select the first UI Policy Action you want to copy.
 
Modify for the Target UI Policy:
Change the "UI Policy" field to your target UI Policy.
Make sure the table/view where the target UI Policy will apply has the field that is defined in the UI Policy Action. If not, change the field name or create it in the table/view.
Adjust any other necessary fields, like "Order".
Right-click the header and select "Insert and Stay": This will create a copy of the action and keep you on the same form.
Repeat steps 5-6: Modify the fields for the target UI Policy and use "Insert and Stay" for each action you want to copy.
 
This step may be error pron if you number of Action items or UI Policy but good with no code and manual click and paste.
 
A small request from my end, If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer‌🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community
MackI | ServiceNow Technical Consultant | DXC Technology Australia | ServiceNow Practice | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia