- 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:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2021 08:46 PM
When I am trying to create a duplicate incident with .newRecord I am getting below error.
FAILED TRYING TO EXECUTE ON CONNECTION glide.3 (connpid=18475): INSERT INTO task (`short_description`,`made_sla`,`upon_reject`,`sys_updated_on`,`a_int_6`,`a_int_1`,`sys_class_name`,`task_effective_number`,`number`,`sys_id`,`sys_updated_by`,`a_int_2`,`opened_by`,`urgency`,`sys_created_on`,`sys_domain`,`state`,`reassignment_count`,`sys_created_by`,`knowledge`,`a_int_3`,`approval`,`impact`,`sys_mod_count`,`active`,`a_int_7`,`priority`,`sys_domain_path`,`opened_at`,`escalation`,`upon_approval`,`a_str_1`,`needs_attention`) VALUES('Test',1,'cancel','2021-08-07 03:44:20',0,1,'incident','INC0010076','INC0010076','fea5a8b52f7db01042162b5df699b64a','Upender.Kumar',1,'a94e5830dbbbb7005027fe1b68961964',3,'2021-08-07 03:44:20','09ff3d105f231000b12e3572f2b4775d',1,0,'Upender.Kumar',0,3,'not requested',3,0,1,0,5,'!!!/!!!/','2021-08-05 10:03:06',0,'proceed','inquiry',0) /* dev90375003, gs:2CF4B3752FB1341042162B5DF699B6F4, tx:dca57b7d2fb5341042162b5df699b6b7 */ Unique Key violation detected by database ((conn=18475) Duplicate entry 'fea5a8b52f7db01042162b5df699b64a' for key 'PRIMARY') : java.sql.SQLIntegrityConstraintViolationException: (conn=18475) Duplicate entry 'fea5a8b52f7db01042162b5df699b64a' for key 'PRIMARY': org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:229)