- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2023 08:44 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2023 09:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2023 09:31 AM
Thank you so much it worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2023 09:15 AM
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