Add catalog item with record producer

nate_weldon1
Kilo Contributor

I have a record producer for off-boarding employees that will create a request, and have also created a catalog item that includes our standard off-boarding services and workflow behind it. I'd like to add that item to the parent request from within the record producer. I've started with the below script but it doesn't add the item. Am I missing something here? I want to call this item from a record producer to control fields on the parent request, and there won't be any situations where the requested_for would add other items. I'd try this from the item but there is no script field.

// Set assignment group based on company
if (producer.company.getDisplayValue()=='Alere Home Monitoring, Inc.'){
current.assignment_group =('b6421fa0780b2080d7b86814a2d7453a');
}
else {
current.assignment_group =('1100424939f3000029478783fb2f5f65');
}
// Set due date
var today = now();
var due = producer.due_date.getDisplayValue();
var diff = gs.dateDiff(today, due, true);

if (diff <= 0){
current.due_date = today;
}
else {
current.due_date = producer.due_date + ' 00:00:00';
}


current.category.setDisplayValue('Human Resources');
current.subcategory.setDisplayValue('Leaver');
current.requested_for=producer.manager;
current.short_description='Leaver - ' + producer.leaver.getDisplayValue() + ' - ' + producer.due_date.getDisplayValue();
current.description+='\nCompany: ' + current.requested_for.company.getDisplayValue();
current.description+='\nLeaver: ' + producer.leaver.getDisplayValue();
current.description+='\nManager: ' + producer.manager.getDisplayValue();
current.description+='\nFinal Day of Work: ' + producer.due_date.getDisplayValue();
current.description+='\nTerminate Network Access: ' + current.due_date;
current.description+='\nEntered By: ' + current.opened_by.getDisplayValue();
current.description+='\nForward Email To: ' + producer.fwdEmailTo.getDisplayValue();
current.description+='\nSpecial Instructions: ' + producer.specInst.getDisplayValue();
current.inert();
//create req item
gs.include('Cart');
var cart = new Cart();
var item = cart.addItem('12b9d91c7cf3340014044a29fd73e137');
cart.setVariable(item,'manager', producer.manager());
cart.setVariable(item,'leaver', producer.leaver());

var rc = cart.placeOrder();
gs.addInfoMessage(rc.number);



//producer.redirect='home.do?';

6 REPLIES 6

mlutfi
Kilo Contributor

here is my code snippet that i use to create a request item from within a request record producer

insertChildren();
function insertChildren() {
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.initialize();
grReqItem.request=current.sys_id;
grReqItem.cat_item='hghghghg'; //insert sys_id of catalog item
grReqItem.insert();
}




Great... I appreciate the reply. 🙂