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

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


}


To only copy few fields, you can do this:



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


        var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


        gr.newRecord();


        gr.yourfield1 = current.yourfield1;


        gr.yourfield2 = current.yourfield2; //as many fields as you want


        gr.setWorkflow(false);


        gr.insert();


}





Abhinay Erra
Giga Sage

There is no direct way for that. You need to map the fields individually.



var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr.initialize();


gr.<field name>=current.<field name>;


...


....


gr.insert();


Thank you so much, again worked perfectly.



Thanks,


Edwin



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


var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr.initialize();


gr.requested_for = current.requested_for;


gr.business_unit = current.business_unit;


gr.watch_list = current.watch_list;


gr.audience = current.audience;


gr.submission_type = current.submission_type;


gr.contract_impacted = current.contract_impacted;


gr.product_line = current.product_line;


gr.request_type = current.request_type;


gr.defect_type = current.defect_type;


gr.department = current.department;


gr.shortdescription = current.shortdescription;


gr.revenue_sla_impacted = current.revenue_sla_impacted;


gr.dollar_impacted = current.dollar_impacted;


gr.work_notes = current.work_notes;


gr.insert();


}


Abhinay Erra
Giga Sage

LOL. Spent time without any credit