Record Producer - Incident/Request - Attachments

Tom Lapkowicz
Tera Expert

Hello. 

 

I have a Record Producer that is set to kick off an Incident in some situations and a Request in other situations, depending on the value of a variable.

 

That part of the process (i.e. kick off Incident or Request) is working as expected.

 

My issue is that if there is an attachment and it is kicking off a Request then the attachment does not get added to the Request (in sys_attachments table it shows the attachment being associated with the Incident table).

 

Anyone have any ideas on how I can set it so that if a Request is being kicked off that the attachment comes with it?

 

Thank you!

1 ACCEPTED SOLUTION

Hi Tom, Sorry I didn't realise you replied.

 

From your shared script there are a few issues.

  • When creating request management records, I'd really push to using the CartJS API as to create records how SN intends CartJS | ServiceNow Developers
  • Attachments are transient before they're set to their final record destination.

You can use the following, after you have the newly redirected target record defined, to move the attachments

var attachment = new GlideSysAttachment();

var agr = attachment.getAttachments(current.getTableName(), current.getUniqueValue());

while(agr.next()){
	agr.setValue('table_name' , '');
	agr.setValue('table_sys_id' , '')
}

View solution in original post

7 REPLIES 7

Kieran Anson
Kilo Patron

Are you able to share how you're targeting two tables in a record producer? My asumption is you're aborting the current action and targeting a different table, for which the attachments won't know where to end up.

A native solution to this is ServiceNow's universal request module which allows you to have a "primary" ticket above business-process specific task types

Hi Kieran.  I am using "current.setAbortAction(true);" to get it to stop from kicking off an Incident and instead creating a Request - does that answer your question?

Can you share the full code being used in your record producer. 

I left out/removed some parts due to privacy issues but hopefully this is enough for you to work with:
 
if (approvedSoftware != 'Not Listed') {
// Create an Incident
    current.category = "requests_wants";
    current.subcategory = "software_install_order";
    current.contact_type = "self-service";
    current.short_description = producer.caller_id.getDisplayValue() + " wants to deploy this application install package: " + producer.name_of_current_install_package;
    current.assignment_group = [removed due to privacy issues] //Service Desk
    current.description = long_description;
    current.watch_list = list;

} else if (approvedSoftware == 'Not Listed') {
    current.setAbortAction(true);
    // Create a Service Request
    var request = new GlideRecord('sc_request');
    request.initialize();
    request.short_description = producer.caller_id.getDisplayValue() + " wants to deploy this application install package that needs to be reviewed/approved: " + producer.enter_the_name_of_the_install_package;
    request.description = "Install package name: " + producer.enter_the_name_of_the_install_package + "\n" + "Install package description: " + producer.enter_a_description_of_the_install_package + "\n" + "Additional details on request:" + "\n" + long_description;
    request.watch_list = list;
    var requestSysId = request.insert(); // Insert the record and get its sys_id

    // Redirect to the Service Request details page
    producer.portal_redirect = [removed for privacy purposes];
} else {
    gs.warn('Unexpected value for approved_software: ' + approvedSoftware);
}