see
bulk create incidents from interactions
(c) Jithender Nayini
var canCreateIncident = false;
if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite()))
canCreateIncident = current.update();
else
canCreateIncident = true;
if (canCreateIncident) {
var inc = new GlideRecord("incident");
inc.initialize();
inc.caller_id = current.opened_for;
inc.short_description = current.short_description;
inc.description = current.u_description;
inc.service_offering = current.u_service_offering;
inc.contact_type = current.type;
if (gs.getProperty("com.snc.incident.create_from_interaction.save") === 'true') {
inc.work_notes = gs.getMessage('Incident created from Interaction {0}', current.number);
var incSysId = inc.insert();
if (incSysId) {
if (gs.getProperty('com.snc.incident.create_from_interaction.copy_attachments' , false) === 'true') {
var serviceInteractionUtils = new global.ServiceInteractionUtils();
serviceInteractionUtils.copyAttachments(current, inc);
}
var interactionRelatedGR = new GlideRecord("interaction_related_record");
interactionRelatedGR.initialize();
interactionRelatedGR.interaction = current.sys_id;
interactionRelatedGR.document_table = 'incident';
interactionRelatedGR.document_id = incSysId;
interactionRelatedGR.insert();
}
}
action.openGlideRecord(inc);
}
create a general request from interactions
where the general request is a catalog item
var canCreateRequest = false;
if ((current.isNewRecord() && current.canCreate()) || (!current.isNewRecord() && current.canWrite()))
canCreateRequest = current.update();
else
canCreateRequest = true;
if (canCreateRequest) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('d95447ce1b973010987d1fc3b24xxxx', 1);
cart.setVariable(item, "onbehalfof_flag", 'Yes');
cart.setVariable(item, "on_behalf_of", current.opened_for);
cart.setVariable(item, "email", current.opened_for.email);
cart.setVariable(item, "short_description", current.short_description);
cart.setVariable(item, "description", current.u_description);
cart.setVariable(item, "related_interaction_record", current.sys_id);
cart.setVariable(item, "service_or_service_offering", current.u_service_offering);
cart.setVariable(item,"contact_type",current.type);
cart.setVariable(item, "assignment_group", current.u_service_offering.support_group);
cart.setVariable(item,"minimum_data_set",current.u_service_offering.u_minimum_data_set);
var rc = cart.placeOrder();
var reqRecord = new GlideRecord('sc_request');
reqRecord.get(rc.sys_id);
reqRecord.requested_for = current.opened_for;
reqRecord.update();
if (rc.sys_id) {
var interactionRelatedGR = new GlideRecord("interaction_related_record");
interactionRelatedGR.initialize();
interactionRelatedGR.interaction = current.sys_id;
interactionRelatedGR.document_table = 'sc_request';
interactionRelatedGR.document_id = rc.sys_id;
interactionRelatedGR.insert();
}
action.openGlideRecord(rc);
}
Comments
Post a Comment