Copying record data to a new record with out saving in ServiceNow
We recently had a requirement to copy data from an existing record to a new record, which traditionally is not super hard, you could use a client script, a business rule, you name it.
However, the issue arose that traditionally when you do this the new record gets inserted. This wasn't going to work for us as we had a flow that kicked off immediately after the record was inserted. This is behaviour we did not want, we wanted the data copied to a new record with out it being saved.
To achieve this, we used a UI Action to harvest the variables on button click, and pass these values using URL navigation to a new record. The fields from the URL automatically get populated into the form. It worked quite well and you can see the simple layout below.
Create the UI Action
- Create a new UI Action
- Set the Onclick value to a function called copy (or similar, your choice).
- Ensure the "Client" checkbox is checked.
- Populate the script box with the following function:
The "Values" variable contains a list of field names that you would like harvested and copied to the new record. Replace the "tableName" with your desired table.
3. Add any conditional logic you would like, to control when the button should be available. As you can see below, we didn't want it available on new Records, and only available for a certain table.
4. That's it! Testing time! Enjoy!