
- 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 01:55 PM
I tested it on my instance and is not giving any error currently. It's creating a new copy with the next autonumber generated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:32 PM
Here you go
if (current.survey_question_2 == 'New Ask based on response') {
var gr= new GlideRecord("table name");
gr.newRecord();
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:39 PM
Hi Abhinay,
Wouldn't this create just a new record(not a duplicate) with default values?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:40 PM
Oops I misread completely. Here is the code for creating a copy
var gr= new GlideRecord('table name');
gr.get(current.getValue('sys_id'));
gr.setWorkflow(false);
gr.insert();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:58 PM
For the next number to be padded use this script
var gr= new GlideRecord(current.getTableName());
gr.get(current.getValue('sys_id'));
gr.number=getNextObjNumberPadded();
gr.setWorkflow(false);
gr.insert();