The CreatorCon Call for Content is officially open! Get started here.

Multiple RITM and Request

Sarthak
Tera Contributor

Hello Team, 

My Requirement is I have an excel sheet consisting of Model, Stockroom and Quantity columns, which is submitted via a catalog item from Portal, we need a separate a RITM-REQUEST for every row in the excel sheet with columns in excel sheet as variable in RITM. 

I have created a Data source, Transform Map with Target Table as <sc_req_item> table and associated Transform Map script of "OnAfter" for the same.

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

var cart = new Cart();

var item = cart.addItem('b79d6a361bac5c109af063d5ec4bcbfc',2); //sysid of item

cart.setVariable(item,'application',source.u_variable1);

cart.setVariable(item,'request_type',source.u_variable2);

cart.setVariable(item,'related_business_application',source.u_variable3);

cart.setVariable(item,'requested_by',source.u_variable4);

var rc = cart.placeOrder();

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

 

The Problem I am facing is for every row in the excel sheet it is creating 2 ritm, One with all fields-variable correct. And one ritm with all the fields empty.

 

And I dont want this extra ritm with empty fields.

 

Can anyone plz help me with solution

 

2 REPLIES 2

Ratnakar7
Mega Sage

Hi @Sarthak ,

To address this issue and avoid creating duplicate RITM records with empty fields, you could modify your script as follows:

(function runTransformScript(source, map, log, target /*undefined onStart*/) {
    // Loop through each row in the source data
    for (var i = 0; i < source.size(); i++) {
        var cart = new Cart();

        var item = cart.addItem('b79d6a361bac5c109af063d5ec4bcbfc', 1); // sysid of item

        cart.setVariable(item, 'application', source.u_variable1.get(i));
        cart.setVariable(item, 'request_type', source.u_variable2.get(i));
        cart.setVariable(item, 'related_business_application', source.u_variable3.get(i));
        cart.setVariable(item, 'requested_by', source.u_variable4.get(i));

        var rc = cart.placeOrder();
    }
})(source, map, log, target);

In this script, a loop iterates through each row in the source data (Excel sheet). For each row, it creates a new cart and adds an item with the provided sys_id. Then, it sets the variables using the data from the corresponding row in the source data. Finally, it places the order for that specific row's data.

 

Thanks,

Ratnakar

Hello Ratnakar thanks for your valuable suggestion, I have tried implementing it but now the transform script not even calling.

I am posting the pic of exact code, can you please check it.

My process, My Excel columns are Model, Stockroom and quantity

I applied Gliderecord to fetch SysId for these ref fields. Then I have applied Cart Api...