- 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:47 AM
I gave that a shot (I think I had already tried it) same result, the attachment was not copied.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:50 AM
I have tried to check if GlideSysAttachment.copy is supported in scooped application but looks it does, can you please check if workaround in below post helps?
https://community.servicenow.com/community?id=community_question&sys_id=0dd98fe5db5cdbc01dcaf3231f9619d5&view_source=searchResult
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 07:01 AM
Tried this and I left in the gr.update(); and still got the same result.
- 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 07:05 AM
You sir are a genius! I added a 5 second timer to pause the workflow and BOOM! there it was.
Thanks everyone for all the help!