How to copy attachment of REQUEST into SC Task table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2024 09:36 PM
Hii all,
I have a requirement of attachment while submit a catalog it generate request give an attachment to it and copy it into sc_task table
how it can be achieve?
Regards,
Suyash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2024 01:04 AM
Hello @Suyash Joshi
If you are thinking I am answering your question from chat gpt, then why you are here, you can also find answers from AI tools or by surfing.
Now coming on your answer-
Whenever we are submitting any request from portal at that time attachments are present on the sc_req_item table not on the sc_request table.
So you need to write br on "sc_req_item" and in code also you need to give
attach.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);
Mark ā Correct if this solves your issue and also mark š Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2024 01:31 AM
Sure, you can achieve this by creating a Business Rule. Here are the steps:
1. Navigate to System Definition > Business Rules.
2. Click on New to create a new Business Rule.
3. Give it a meaningful name, for example, "Copy Attachment to SC Task".
4. Select the table as "sc_req_item" (Service Catalog Request Item).
5. Set the "When to run" as "After" and "Insert".
6. In the "Advanced" tab, write the script to copy the attachment from the Request to the Task.
Here is a sample script:
javascript
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'sc_request');
gr.addQuery('table_sys_id', current.request.sys_id);
gr.query();
while (gr.next()) {
var gr2 = new GlideRecord('sys_attachment');
gr2.initialize();
gr2.name = gr.name;
gr2.content_type = gr.content_type;
gr2.size = gr.size;
gr2.table_name = 'sc_task';
gr2.table_sys_id = current.sys_id;
gr2.insert();
}
})(current, previous);
This script will copy all attachments from the Request to the Task when a new Request Item is created.
Remember to test this in a sub-production instance before deploying it to production.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER