- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 01:50 AM
Hi All,
I want to create a catalog item which will help to import the file to CMDB table.My thought is on submit of the the request trigger the data source and pass the attachment to it.
But don't know how to achieve it.
Please let me know if any suggestion on this
Thanks,
Neethu
Solved! Go to Solution.
- 6,353 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 05:59 AM
Hi Neethu,
That's correct.
1) Have business rule after insert on RITM table which runs only for that particular Catalog Item.
2) Have a data source, transform map and field map created as usual. coalesce etc will be present
3) Have scheduled import created with this data source with active= false, run as administrator since it will be triggered from script. In left nav type Scheduled Imports and create new
4) in the business rule condition check whether the RITM has attachment then only run the business rule and have following script
Business rule condition:
current.hasAttachments()
//extra check you can have is whether it is csv or xls based on data source attachment file type
Business rule script:
var dataSourceSysId = ''; // sys_id of the data source you created in step 2
var schImp_GR = new GlideRecord('scheduled_import_set');
schImp_GR.addQuery('data_source',dataSourceSysId);
schImp_GR.query();
if(schImp_GR.next()){
gs.executeNow(schImp_GR); // use this if it is in scoped app
//SncTriggerSynchronizer.executeNow(schImp_GR); // if in non-scope app i.e. global
// the above 2 lines will start the import process, etc automatically
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 07:02 AM
Hi Sunil,
First of all why you are creating data source through script. Steps are as belows:
1) Data source, transform maps, field maps should be present
2) through BR you need to attach the file to data source
3) Have scheduled data import which is active false
4) trigger the transformation by triggering the scheduled data import
There is error in your code: change to below; I have removed the quotes around that variable highlighted in bold
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', dataSourceID);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 01:42 AM
Hello Ankur,
I have used the method given by you
1) Have business rule after insert on RITM table which runs only for that particular Catalog Item.
2) Have a data source, transform map and field map created as usual. coalesce etc will be present
3) Have scheduled import created with this data source with active= false, run as administrator since it will be triggered from script. In left nav type Scheduled Imports and create new
I have also added the code GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', dataSourceID);
to add attachment to Data source. The data source gets created but attachment is missing. I have hard coded the dataSourceID with SysID of data source in the BR
(function executeRule(current, previous /*null when async*/) {
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', 'c6932bd9db402300a7700d53ca961962');
// Add your code here
var dataSourceSysId = 'c6932bd9db402300a7700d53ca961962'; // sys_id of the data source you created in step 2
var schImp_GR = new GlideRecord('scheduled_import_set');
schImp_GR.addQuery('data_source',dataSourceSysId);
schImp_GR.query();
if(schImp_GR.next()){
//gs.executeNow(schImp_GR); // use this if it is in scoped app
SncTriggerSynchronizer.executeNow(schImp_GR); // if in non-scope app i.e. global
// the above 2 lines will start the import process, etc automatically
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 01:48 AM
Hi Sunil,
Can you check any errors while copying the attachments in system logs?
It should work fine. Can you check whether by the time the code runs the attachment is present on RITM or not?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 01:54 AM
Hi Ankur,
I have tried the same for "Update " in BR. Attachment was present in RITM and i updated it. We still could not see the attachment moving to Data source. Any idea if we can delay the BR so that we give time for attachment to load to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 02:51 AM
I used the following code in BR to see if attachment is present while we are creating data source
var Att = new GlideRecord('sys_attachment');
Att.addQuery('table_sys_id', current.sys_id);
Att.query();
if(Att.hasNext())
{ gs.log("RITM has attachment");}
else {gs.log("RITM has no attachment");}
"RITM has attachment" gets printed in logs which means that attachment is present.. Not sure why is it not getting attached to data source