Create records based on quantity field in Request management

Thrupthi1
Tera Contributor

I have a requirement to create the multiple records automatically when the ticket is created.

Ticket : RITM

I have used a UI action to create the record automatically at the hardware table and it works for single record

But now I have a requirement to create multiple records when quantity is more than 1

example when someone submits the catalog request, if they select quantity as 5 then system needs to create 5 records for the same

I have sample script here for UI action which copies the variable value and maps to table field when UI action is clicked

var asset = new GlideRecord("alm_hardware");
asset.initialize();
asset.asset_function = "testing";
asset.location = current.variables.destination_location;
asset.insert();
 
Can anyone help me on how to create a array and use this quantity to create multiple records please
Thanks for the help in advance
1 ACCEPTED SOLUTION

Devender Kumar
Tera Guru
Tera Guru

Hi @Thrupthi1 ,

Try script like below.

var quantity=current.quanity;
for(var i=0;i<quantity;i++)
{
var asset = new GlideRecord("alm_hardware");
asset.initialize();
asset.asset_function = "testing";
asset.location = current.variables.destination_location;
asset.insert();
}

 

If my answer resolves your issue then don't forget to mark it as correct/helpful.

Regards,

Devender

View solution in original post

6 REPLIES 6

Thank you so much it worked

Prinssi
Mega Sage

It sounds like you want to use a for loop to create these hardware records:

 

 

var quantity = current.quantity; //get the quantity from the RITM
for (var i = 0; i < quantity; i++) 
{
//Insert your GlideRecord logic here
};

 

 

When quantity is 1, that is more than 0, which means the loop will run once but stop on the next round.  But, when the quantity increases, this will run as many times as necessary.

 

Chuck does a great job explaining more in the following video: Learn JavaScript on the Now Platform: Lesson 16 - The for loop