Implementing Copy Functionality from a Related List declarative action using UI Builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Everyone,
I'm working on a requirement in ServiceNow Workspace (UI Builder) and would appreciate some guidance on the recommended implementation approach. I am new to UI builder, so I may not be aware of the best practices.
Requirement:
I need to have a Related List Declarative Action configured on a related list in Workspace. Clicking this declarative action should open a modal.
The modal should contain:
- A reference field that allows the user to select an existing record.
- A Copy button that creates a new record by copying the field values from the selected record.
The new record should inherit all field values from the selected record, with the exception of the Status field. The Status of the newly created record should always be set to New, regardless of the status of the selected record.
I'm looking for the recommended approach or best practice for implementing this functionality. Any guidance, implementation examples, or relevant documentation would be greatly appreciated.
Thank you in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Hey @D Sha,
Do the copy logic in a Transform data resource, not a Create Record data resource with hardcoded templateFields. Since you want to inherit every field except Status, you need a loop, not a field-by-field map. Something like this on the Transform's server script:
(function execute(inputs, output) {
var source = new GlideRecord('your_table_name');
if (source.get(inputs.source_sys_id)) {
var target = new GlideRecord('your_table_name');
target.initialize();
for (var field in source) {
if (field != 'sys_id' && field != 'status' && field != 'number') {
target.setValue(field, source.getValue(field));
}
}
target.setValue('status', 'new');
output.new_sys_id = target.insert();
}
})(inputs, output);Set Mutates server data to true on the data resource so it runs as a mutation rather than getting cached like a query. Pass the reference field's selected sys_id in as an input variable, wire the button's onClick to execute the data resource, and handle the "operation succeeded" event to close the modal and refresh the related list.
For the modal itself, the wiring is the standard declarative action pattern: an action assignment in sys_declarative_action_assignment on the List - Related component, a page variant on your UXF page set to open as a Dialog/Modal, and a UXF Client Action that fires the Open Modal event. That part is boilerplate once you've seen it once, the field-copy loop above is really the only custom logic you need.
Thank you,
Vikram Karety
Octigo Solutions INC