- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 05:06 AM - edited 07-06-2023 05:21 AM
Hi Developers,
I have a requirement to create Requested Items using data in Excel. This file will also contain the variables that are required to create the RITM if created using catalog item. But here the data will be fetched using an excel file.
I tried to achieve this using transform map scripting, but i am getting 2 records created. the one showing in the import set is empty(duplicate).but when searched in sc_rec_item table there is another record with the datails i have provided
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('10ec16b3c61122760021a44ec7746bb3');
cart.setVariable(item, 'special_software_requirements', source.u_special_software);
var rc = cart.placeOrder();
and if i add the ignore = true; at the last
cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('10ec16b3c61122760021a44ec7746bb3');
cart.setVariable(item, 'special_software_requirements', source.u_special_software);
var rc = cart.placeOrder();
ignore = true;
import set is ignored but the record is inserted with the details provided.
no duplicate is created
can someone help me with a solution
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 07:05 AM
you can set the import set field using onBefore transform script for each row since you will get to know the RITM number
you can use source object and update it; remember this is a workaround
Anyhow import set table gets cleaned up every 7 days by OOB scheduled job so this will be available only for 7 days
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('10ec16b3c61122760021a44ec7746bb3');
cart.setVariable(item, 'special_software_requirements', source.u_special_software);
var rc = cart.placeOrder();
var ritmSysId;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", rc.sys_id);
gr.query();
if (gr.next()) {
ritmSysId = gr.getUniqueValue();
}
source.sys_target_table - gr.sys_class_name;
source.sys_target_sys_id = ritmSysId;
source.update();
ignore = true;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 06:01 AM
RITM will get created and import set record will be ignored because you are using ignore=true and this is the correct way
since your requirement is just to insert data into RITM and not the target table of that transform map(even though it's RITM in this case) so it makes sense to ignore since that record which gets created via import set doesn't make sense as it won't have any variables associated to it
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 06:22 AM
but how to I map the record that got created from script to the import set "Target record" field,
because later on at some stage if the client asks which record got created from which import set.
to back track
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 07:05 AM
you can set the import set field using onBefore transform script for each row since you will get to know the RITM number
you can use source object and update it; remember this is a workaround
Anyhow import set table gets cleaned up every 7 days by OOB scheduled job so this will be available only for 7 days
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('10ec16b3c61122760021a44ec7746bb3');
cart.setVariable(item, 'special_software_requirements', source.u_special_software);
var rc = cart.placeOrder();
var ritmSysId;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", rc.sys_id);
gr.query();
if (gr.next()) {
ritmSysId = gr.getUniqueValue();
}
source.sys_target_table - gr.sys_class_name;
source.sys_target_sys_id = ritmSysId;
source.update();
ignore = true;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader