- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 04:52 AM
Hello,
I want to duplicate a record in a business rule. How the script should look like?
When the state changes from A to B, I want a new record to be created with exactly the same values of the record that triggered the business rule, and only to have a different number and the field "flag" to be true.
How the script should look like? Does it need to be a before or after BR?
Thank you,
Smith.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 05:43 AM
var gr= new GlideRecord(current.getTableName());
gr.get(current.sys_id);
gr.number=new NumberManager(current.sys_meta.name).getNextObjNumberPadded();
gr.setWorkflow(false);
//you can update other fields here
gr.insert();
Try above

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 04:58 AM
Hi Smith,
Here you go:
var gr= new GlideRecord('table name');
gr.get(current.getValue('sys_id'));
gr.setWorkflow(false);
gr.insert();
Also, I recommend to check the below link :
https://community.servicenow.com/community?id=community_question&sys_id=35a443e9dbd8dbc01dcaf3231f96191c
Mark Correct/Helpful, if applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 05:43 AM
var gr= new GlideRecord(current.getTableName());
gr.get(current.sys_id);
gr.number=new NumberManager(current.sys_meta.name).getNextObjNumberPadded();
gr.setWorkflow(false);
//you can update other fields here
gr.insert();
Try above
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 05:49 AM
One small change,
var gr= new GlideRecord(current.getTableName());
gr.newRecord(); // to set the default values
gr.get(current.sys_id);
gr.number=new NumberManager(current.sys_meta.name).getNextObjNumberPadded();
gr.setWorkflow(false);
//you can update other fields here
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 06:09 AM
I think that is not required as it is copying all the fields.