- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 11:35 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 01:36 AM
Yes, it is possible to automatically move or copy attachments from a task to its parent RITM in ServiceNow. You can achieve this by creating a Business Rule or a Scripted REST API. Here are the steps to create a Business Rule: 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, "Move Attachments to RITM". 4. Select the table as "sys_attachment" (This is the table where all attachments are stored). 5. In the "When to run" section, select "After" and "Insert". 6. In the "Advanced" tab, write a script to move the attachment from the task to the RITM. Here is a sample script: javascript (function executeRule(current, previous /*null when async*/) { var gr = new GlideRecord('sc_task'); if (gr.get('sys_id', current.table_sys_id)) { if (gr.request_item.nil()) { return; } current.table_name = 'sc_req_item'; current.table_sys_id = gr.request_item; current.update(); } })(current, previous); This script checks if the attachment is associated with a task. If it is, it moves the attachment to the associated RITM. Please note that this script is a simple example and may need to be adjusted to fit your specific needs. Always test scripts in a non-production environment before deploying them to production. Also, keep in mind that this will move the attachment from the task to the RITM, not copy it. If you want to keep a copy of the attachment on the task, you would need to modify the script to create a copy of the attachment instead of moving it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 12:08 AM
Hi @Jacob64
you can follow the below link which describes the solution to similar requirement
Copy Attachment from RITM to SC Task on request submit and updates from portal.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 12:32 AM
Hi Jacob,
You can do it by changing the Table sys id of attachment which is record sys id of catalog task to RITM sys id. To do so you need to write a After or Async BR for catalog task table like below:
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_sys_id', current.getUniqueValue());
grAttachment.query();
while(grAttachment.next()){
grAttachment.setValue('table_sys_id', current.getValue('request_item'));
grAttachment.update();
}
This will update the Attachment record to display on RITM and not on Task. It won't keep the attachment at Task table and will only show in RITM record.
Note:
Since you're modifying an OOTB table record please make sure you have all the rights to do it. Open sys_attachment table and see if you're able to modify Table sys id column of any record.
Also this BR make take sometime to run depending upon the instance and records present in Attachment table. (May encounter performance issues)
If my answer helps then please mark it correct.
Thanks,
Utpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 01:36 AM
Yes, it is possible to automatically move or copy attachments from a task to its parent RITM in ServiceNow. You can achieve this by creating a Business Rule or a Scripted REST API. Here are the steps to create a Business Rule: 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, "Move Attachments to RITM". 4. Select the table as "sys_attachment" (This is the table where all attachments are stored). 5. In the "When to run" section, select "After" and "Insert". 6. In the "Advanced" tab, write a script to move the attachment from the task to the RITM. Here is a sample script: javascript (function executeRule(current, previous /*null when async*/) { var gr = new GlideRecord('sc_task'); if (gr.get('sys_id', current.table_sys_id)) { if (gr.request_item.nil()) { return; } current.table_name = 'sc_req_item'; current.table_sys_id = gr.request_item; current.update(); } })(current, previous); This script checks if the attachment is associated with a task. If it is, it moves the attachment to the associated RITM. Please note that this script is a simple example and may need to be adjusted to fit your specific needs. Always test scripts in a non-production environment before deploying them to production. Also, keep in mind that this will move the attachment from the task to the RITM, not copy it. If you want to keep a copy of the attachment on the task, you would need to modify the script to create a copy of the attachment instead of moving it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 07:29 AM
Dear all,
Tanks for your reactions sofar.
I read a lot of negative comments about copying files to the RITM above because that can cause performance problems. So that's not the first solution we want to use.
I also get the feeling that adjusting system properties changing the location is not good for the ootb situation.
So that is also not directly top of mind.
We do however use a related list to show the attachments from the RITM in the sctask and try to make a new one that does the other way around and showing the attachments of all related sctask to that RITM.
We once managed to create a query that gives us the right information. But as I'm not a developer at all it is not simple for me to get a working query.
With the following code i'm able to show all attachments related to a sctaks that is not only related to that specific RITM:
When reading this you may think what a fool this can be done much easier like this or that. As I already mentioned I'm not a developer at all so you're probably right to think the same.
But is you have a good working query for that please let me know!
KR, Jacob52.