Create a RITM From transform map scripting

Appu
Tera Guru

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

Appu_0-1688644365181.png

 

Appu_3-1688644958348.png

 

 

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.

Appu_1-1688645965588.png

no duplicate is created

Appu_2-1688646076106.png

 

 

 can someone help me with a solution

1 ACCEPTED SOLUTION

@Appu 

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.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Appu 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.

Appu_0-1688649667461.png

to back track

 

@Appu 

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.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader