
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:08 PM
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') {
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 01:46 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:18 PM
Hi Edwin,
It would be an after business rule and goes something like this: (Untested code)
var gdt= new GlideDateTime();
current.actual_completion_date.setValue(gdt);
if (current.survey_question_2 == 'New Ask based on response') {
current.insert();
}
This would create an exact copy of the current record, if you need any changes, that can be incorporated as well. (Related lists won't be carried over - additional scripting required)
Edit: Unless there are any primary key violations. In that case you can assign new values for those fields and then insert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:33 PM
When I try this, it works but is giving an exception because the business rule is firing out a second time after the duplicate is created. (Since the duplicate will have the same choice as well)
The only solution I can think of is: Writing this as an after update business rule, so that it won't run again when new record is inserted. The drawback is that this won't take effect on insert. Let's hope other community experts have a better solution for this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:53 PM
Try this:
- var gdt= new GlideDateTime();
- current.actual_completion_date.setValue(gdt);
- if (current.survey_question_2 == 'New Ask based on response') {
- current.number = getNextObjNumberPadded();
- current.insert();
- }