- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 05:43 AM
I created a workflow script to create a record in a scoped application from a sc_request that is working great. The problem I am having is I'd like to copy any attachments that are added to the Request onto the new record. I tried to use the GlideSysAttachment.copy function but I must be doing something wrong. See the script below. Any suggestions on what I am doing wrong?
Thanks in advance.
var gr = new GlideRecord('x_smcit_siq_pet_table');
gr.initialize();
if (current.variables.customer_name == '') {
var name = new GlideRecord('x_smcit_siq_pet_siq_customers');
name.addQuery('name', current.variables.first_name + ' ' + current.variables.last_name);
name.query();
while (name.next()) {
gr.setValue('customer', name.sys_id);
}
gr.setValue('customer_email', current.variables.email_address);
gr.setValue('customer_number', current.variables.customer_id);
gr.setValue('sleeper_id', current.variables.sleeper_id);
}
else {
gr.setValue('customer', current.variables.customer_name);
var name = new GlideRecord('x_smcit_siq_pet_siq_customers');
name.addQuery('sys_id', current.variables.customer_name);
name.query();
while (name.next()) {
gr.setValue('customer_email', name.getValue('email'));
gr.setValue('customer_number', name.getValue('customer_id'));
gr.setValue('sleeper_id', name.getValue('sleeper_id'));
}
}
gr.setValue('description', current.variables.description);
gr.setValue('issue_type', current.variables.issue_type.getDisplayValue());
gr.setValue('issue_sub_type', current.variables.issue_subtype);
gr.setValue('current_mac_address', current.variables.current_mac_address);
gr.setValue('new_mac_address', current.variables.new_mac_address);
gr.setValue('type_of_router', current.variables.router_type);
gr.setValue('number_of_routers', current.variables.number_of_routers);
gr.setValue('pump_lights', current.variables.pump_lights);
gr.setValue('pump_on_for_investigation', current.variables.pump_on);
gr.setValue('firewall', current.variables.firewall);
gr.setValue('cascaded_network', current.variables.cascaded_network);
gr.setValue('order_number', current.variables.order_number);
gr.setValue('components_for_product_name', current.variables.components_for_product_name);
gr.setValue('line_not_added_to_sleepiq', current.variables.line_not_added_to_sleepiq);
gr.setValue('component_to_be_added_to_siq', current.variables.component_to_be_added_to_siq);
gr.setValue('customer_number_mismatch', current.variables.customer_number_mismatch);
gr.setValue('use_siq_customer_number', current.variables.use_siq_customer_number);
gr.setValue('component_out_of_bom', current.variables.component_out_of_bom);
gr.setValue('missing_component', current.variables.missing_component);
gr.setValue('line_number_of_component', current.variables.line_number_of_component);
if (current.variables.description.length > 80) {
gr.setValue('short_description', current.variables.description.substring(0, 79));
}
else {
gr.setValue('short_description', current.variables.description);
}
var sysID = gr.insert();
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'x_smcit_siq_pet_table', sysID);
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:52 AM
Where is this code within the workflow? I ask because it is important to understand the execution order of the catalog and I suspect maybe the requested item may not be inserted yet thus the attachments aren't available to copy from. If this script is at the beginning of the workflow the sc_req_item hasn't been inserted yet and nor has the sc_request. Once the workflow reaches a stopping point like waiting for an approval or wait for condition or timer then the sc_req_item and then sc_request is inserted. By putting in a short timer, you are giving the records a chance to insert.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:02 AM
Are you able to get the created record's sys_id on x_smcit_siq_pet_table table? and are you trying to copy the attachment from sc_request table or sc_req_item table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:17 AM
The attachment is attached by default on the sc_req_item table so that's where I'm trying to copy it from. I've also tried both using var sysID = gr.insert(); to get the sys_id of the x_smcit_siq_pet_table record as well as just using gr.sys_id with the same results, nothing showing up on the new record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:32 AM
I just went in and added a log statement to check the sys_id's and they the ones logged for the variable sysID and for current.sys_id match the new record in the scoped app and the requested item respectively.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:41 AM
Hi Tate,
Try adding gr.update(); after GlideSysAttachment.copy('sc_req_item', current.sys_id, 'x_smcit_siq_pet_table', sysID); once & check.
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response,