//get the sys_id of the original RITM
var originalSysId = current.getUniqueValue();
//set the number field to blank so that the new RITM gets a new number
current.setValue('number','');
//duplicate the RITM
newSysId = current.insert();
//find the variables and copy them to the new RITM
var mtomGR = new GlideRecord('sc_item_option_mtom');
mtomGR.addQuery('request_item=' + originalSysId);
mtomGR.query();
while (mtomGR.next()){
var optionGR = new GlideRecord('sc_item_option');
optionGR.get(mtomGR.sc_item_option.getValue());
var newOptionSysId = optionGR.insert();
var newMtomGR = new GlideRecord('sc_item_option_mtom');
newMtomGR.initialize();
newMtomGR.setValue('request_item',newSysId);
newMtomGR.setValue('sc_item_option',newOptionSysId);
newMtomGR.insert();
}
//copy the multirow variable set if any
var mvrsGR = new GlideRecord('sc_multi_row_question_answer');
mvrsGR.addEncodedQuery('parent_id=' + originalSysId);
mvrsGR.query();
while(mvrsGR.next()){
var optionMvrsGR = new GlideRecord('sc_item_option');
optionMvrsGR.get(mvrsGR.sc_item_option.getValue());
var optionMvrsSysId = optionMvrsGR.insert();
mvrsGR.setValue('parent_id',newSysId);
mvrsGR.setValue('sc_item_option',optionMvrsSysId);
mvrsGR.insert();
}