How to duplicate a record in a business rule?

Smith Johnson
Tera Guru

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.

1 ACCEPTED SOLUTION

Upender Kumar
Mega Sage
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

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

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

Upender Kumar
Mega Sage
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

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();

I think that is not required as it is copying all the fields.