Automate Data import from Excel File Attachment via Catalog item along with request number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi all,
So i refered this post for Automating data import from excel file which is a attachment via catalog item ( link to the article: https://www.servicenow.com/community/developer-blog/automate-data-import-from-excel-file-attachment-...)
Based on the same i created a business rule which works fine, it does import the data from the sheet to the custom table created.
Business Rule:
When: after
order: 100
Insert
filter: item = Import user(catalog item name)
Table : Request item [sc_req_item]
When i Upload another file then the record which is previously uploaded gets the current number but the new records goes empty.
image 1: after 1st sheet is uploaded
Image 2: after sheet 2 is uploaded
i have attached both excel sheets used
please help me find a solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SreeragM
Your Business Rule runs immediately after the catalog item is submitted → it copies the Excel attachment → triggers the scheduled import → but at that moment the data has not yet been inserted into your custom table (u_users_demo).
So when your updateRequestNumber(current.number) runs, there are either no records yet or only older ones from the previous import. That’s why:
First upload → nothing updated (because no records yet).
Second upload → it updates the records from the previous import (because now they exist).
You need to update u_request_number after the import is finished.
Try use an onAfter transform script. See an example of code:
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(source.sys_import_set.sys_attachment.table_sys_id)) {
target.u_request_number = reqItem.number;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
@Rafael Batistot Should add this script in the data source or in the BR itself.
It would be helpful if you could give the complete process of the changes that i need to make.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
In your BL call:
updateRequestNumber(current.number);
Remove this and add a onAfter scrip in your transformap