Create Multiple RITMs Under Same REQ Using the UI Action

Priya_22
Tera Contributor

Hi All,

 

I have a UI Action that runs on the alm_hardware table. When assets are selected and the button is clicked, it submits the RITMs based on the number of assets selected, with each RITM associated with the REQ. Below is the script used to achieve this:

 

var configId = current.ci.sys_id;
var cartId = GlideGuid.generate(null);
var wasteCart = new Cart(cartId);
var item = wasteCart.addItem('bc94067c978516144c913b6e6253af41', 1);
wasteCart.setVariable(item, "u_item_ewaste", configId);
wasteCart.setVariable(item, "u_previous_state", current.install_status);
var rc = wasteCart.placeOrder();

var ritm = new GlideRecord('sc_req_item');
ritm.addEncodedQuery('cat_item=bc94067c978516144c913b6e6253af41^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^variables.7cbe614b97091a104c913b6e6253af81=' + configId);
ritm.orderByDesc("created");
ritm.query();

if (ritm.next()) {
    current.install_status = 500;
    current.update();
} else {
    gs.log("RITM not created hence status is not changed for serial number: " + current.serial_number, 'eWaste Logs');
}

 

Now, I have a requirement: when the user selects 10 assets in the table and clicks the button, it should create 10 RITMs under a single REQ. Please let me know how this can be achieved.

 

Regards,

Priya

5 REPLIES 5

SumanKumarM
Tera Contributor

Hello Priya,

I might try like below,

Create a function(selectedAssets). Iterate through this list of selected Assets, create a RITM and associate it to  the same Request. Please let me know if you need more help.

 

Please mark it helpful, if it helps you in start working on it.

 

BR,

Suman.

 

 

Hi @SumanKumarM 

 

Thank you for your response. If possible could you please help me with the sample script? 

Hello Priya,

I hope below sample code might help you to complete your task.

var assetList = ["P1000000", "P1000001", "P1000002"];
//sc_request=29b61af9835d521002bef855eeaad3db
//sc_cat_item=aa9dd773774211105e3db2a07b5a998a

if(assetList.length > 0){
assetList.forEach(function(asset){
    gs.info("Name:"+asset);
    var grRITM = new GlideRecord("sc_req_item");
        grRITM.initialize();
        grRITM.setValue("cat_item","aa9dd773774211105e3db2a07b5a998a");
        grRITM.setValue("request","29b61af9835d521002bef855eeaad3db");
        grRITM.setValue("requested_for","6816f79cc0a8016401c5a33be04be441");
        grRITM.setValue("quantity","1");
        grRITM.insert();
});
}

Please mark it helpful, if my sample code helps you in anyway.

 

BR,

Suman.

Hi @SumanKumarM ,

 

Thank you! But I would like to know how to retrieve the list of selected assets using a UI action in the list view.

For example, when a user selects assets in the list view and clicks the created UI button, it should submit RITMs under the same REQ.

 

Regards,

Priya