The CreatorCon Call for Content is officially open! Get started here.

Business Rule - Create copy of current item?

Edwin Fuller
Tera Guru

Hello everyone

I need to create a duplicate of the current item whenever a field is answered a certain way; Is this possible using business rule script? The duplicate would get created when the field "survey_question_1" equals "New ask based on response". Examples would be great!!

Current Business Rule script

var gdt= new GlideDateTime();

current.actual_completion_date.setValue(gdt);

if (current.survey_question_2 == 'New Ask based on response') {

}

1 ACCEPTED SOLUTION

Thank you Abhinay, the script you provided below works perfectly. My next ask is how can I create a copy without copying all of the fields, only the fields that I want/need?



if (current.survey_question_2 == 'New Ask based on response') {


var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr.newRecord();


gr.insert();


}


View solution in original post

19 REPLIES 19

You need to set workflow to false


I wrote this only on update so it works without that statement.


I tried with insert too and used setworkflow(false) but that didn't work in my instance. Don't know where I went wrong. I tried that with both after and before.


I believe you should not use current.insert(). It will give you unique key violation error. Instead query a new GlideRecord and insert as shown in my script


The statement current.number... before insert() will solve that unique key violation issue. But I guess its just another way.


I don't think so. You will still get the error.