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

Michael Kaufman
Giga Guru

I think the problem is with the record producer, you can't use current.insert(). Record Producers insert records with backend code. However, that is a problem because the cart needs the Request to create the Requested Item.

If you don't have luck with the cart method, you can use this Business Rule I have. I wouldn't use it if there are a lot of Record Producers at your company.



Business Rule: Create Req Item for //Your Condition
Table: Request
When: async
Insert: true
Condition: //Your Condition to create Requested Item, like current.contact_type == 'self-service'
Script:
createRequestItem();
function createRequestItem() {
//Check for Existing Request Item
var grRequestItem = new GlideRecord ("sc_req_item");
grRequestItem.addQuery('parent', current.sys_id);
grRequestItem.addQuery(//Your Duplicate Record Check Here);
grRequestItem.query();
//No Request Item Found, Create
if (grRequestItem.getRowCount() == 0) {
grRequestItem.initialize();
grRequestItem.assignment_group = current.assignment_group;
grRequestItem.short_description = current.short_description;
grRequestItem.description = current.description;
grRequestItem.due_date = current.due_date;
grRequestItem.description = current.description;
grRequestItem.cat_item = '12b9d91c7cf3340014044a29fd73e137;;
grRequestItem.cmdb_ci = current.cmdb_ci;
grRequestItem.parent = current.sys_id;
grRequestItem.request = current.sys_id;
grRequestItem.insert();
}
}


alhicks
Tera Guru

Hey Nate, were you able to get this working? We have a record producer that we're needing a another catalog item add to the Request, if a certain option is picked on a variable.


No luck yet, haven't been focusing on it though. I may head in a different direction and try an order guide, even though it would be a one page order guide.


Ok, thank you for the reply.