- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 11:58 PM
Hi Team,
I have a issue as I have created the below rest message and everytime on update also it is sending same attachment twice.
How to control this ??
I have used After BR Insert
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:05 AM
Hello @SandeepKSingh ,
Duplicate is being sent because you are fetching all the attachments (every time) while sending the update.
Either you can -
1. Fetch only latest attachment.
2. Use 'Hash' key/column on attachment records and compare with previous attachments so sent. It will fetch only latest attachment.
Hope it helps.
If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.
Regards,
Shubham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 07:17 AM
Adding to @ShubhamGarg you can update the script like the below
Check if you are getting 200 and check for Existing attachment by using "Get" Method and if exisits don't send else send.
and After this call your function "sendAttachments".
I hope that should work
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:05 AM
Hello @SandeepKSingh ,
Duplicate is being sent because you are fetching all the attachments (every time) while sending the update.
Either you can -
1. Fetch only latest attachment.
2. Use 'Hash' key/column on attachment records and compare with previous attachments so sent. It will fetch only latest attachment.
Hope it helps.
If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.
Regards,
Shubham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 02:05 AM
Thanks Shubham will try.. can you provide sample code??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 03:12 AM
Hello @SandeepKSingh ,
1. To fetch latest record of given table, you can always use orderByDesc function of GlideRecord class. Sample code -
.orderByDesc('sys_created_on');
2. You can use hash query. Sample code -
.addEncodedQuery('table_sys_id=' + <object>+ '^hash=' + <appropriate object>.hash);
In both point 1 and point 2, you would need some array of sys_ids to compare with. You can use your Outbound Integration Logs, if defined.
If you do not have list of sys_ids to compare with and you have access to Integrated ServiceNow instance using attachment API, then what can be done is to remove all attachments (count = N), then copy all attachments using your existing logic(new count = N+1).
If my response helps you in any way, kindly mark it as Accepted Solution/Helpful and help in closing this thread.
Regards,
Shubham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 07:17 AM
Adding to @ShubhamGarg you can update the script like the below
Check if you are getting 200 and check for Existing attachment by using "Get" Method and if exisits don't send else send.
and After this call your function "sendAttachments".
I hope that should work
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/