Create Bulk RITM and single Request from Excel

Michael51
Tera Guru

Hello All,

I have an Requirement to create Bulk RITM' from Excel Sheet data , in Excel sheet we get Variable values 

1. Name of the Moniter -  variable backend value - u_name_moniter

2. Description - u_description 

So now I need to get the data from Excel sheet and then create one Request for each excel and then create RITM as per the columns in excel , if we have 20 columns we need to create 20 RITM's 

 

can anyone help me with this 

 

@jaheerhattiwale 

1 ACCEPTED SOLUTION

Hi @Michael51 

You can load the excel into staging table and transform using transform map.

In your transform map use below logic in onComplete script.

Try this code :

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    var impSet = import_set.sys_id ;

    var cartId = GlideGuid.generate(null);
    var cart = new Cart(cartId);
    var gr = new GlideRecord('u_ritmload'); // give your staging table here
    gr.addQuery('sys_import_set='+impSet);
    gr.query();
    while (gr.next()) {

       var item = cart.addItem('1391a4db070630100b36f6fd7c1ed0c2', 1); //give the catalog item sysid
        cart.setVariable(item, 'mutliline', gr.u_col1 ); //add all your variable details here
        cart.setVariable(item, 'mutliline', gr.u_col2 ); //add all your variable details here

    }
    var req_id = cart.placeOrder();
    gs.info("number"+req_id.number);

})(source, map, log, target);

 

I've tried this and it's working.

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

15 REPLIES 15

Hi @Michael51 

You can load the excel into staging table and transform using transform map.

In your transform map use below logic in onComplete script.

Try this code :

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    var impSet = import_set.sys_id ;

    var cartId = GlideGuid.generate(null);
    var cart = new Cart(cartId);
    var gr = new GlideRecord('u_ritmload'); // give your staging table here
    gr.addQuery('sys_import_set='+impSet);
    gr.query();
    while (gr.next()) {

       var item = cart.addItem('1391a4db070630100b36f6fd7c1ed0c2', 1); //give the catalog item sysid
        cart.setVariable(item, 'mutliline', gr.u_col1 ); //add all your variable details here
        cart.setVariable(item, 'mutliline', gr.u_col2 ); //add all your variable details here

    }
    var req_id = cart.placeOrder();
    gs.info("number"+req_id.number);

})(source, map, log, target);

 

I've tried this and it's working.

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hi @Voona Rohila ,

does this create Request as well ? How should I create Request and associate all RItM to it

Yes the above logic creates one request with multiple RITM'S.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Thanks will implement this and will let you know the output

@Voona Rohila  , I could not get data from excel sheet , it is showing as undefined in the variable name , how can get the description information from excel and then pass that into variable