create records in custom table when record inserted in RITM table

Rajkumar Bommal
Tera Contributor

Hi 
I have created a catalog item with a list collector variable, when i selected 10 users in list collector, in ritm record it will show the selected users.
i want to create 10 user records in custom table with RITM number as same as generated ritm record in sc_req_item

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajkumar Bommal 

if you are using flow then you can iterate over that list collector and then create record

something like this, but please enhance as per your requirement

AnkurBawiskar_0-1741166804704.gif

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Rajkumar Bommal 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Rajkumar Bommal 

You can script it out using loop...

(function executeRule(current, previous /*null when async*/) {

// Access the List Collector variable (replace 'u_selected_users' with your variable name)
var users = current.variables.u_selected_users;

if (users) {
var userArr = users.split(',');
for (var i = 0; i < userArr.length; i++) {
var userSysId = userArr[i].trim();
if (userSysId) {
var gr = new GlideRecord('u_ritm_users'); // custom table
gr.initialize();
gr.u_ritm = current.sys_id; // reference to RITM
gr.u_user = userSysId; // user reference
gr.u_ritm_number = current.number; // store RITM number (optional)
gr.insert();
}
}
}

})(current, previous);

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ļ”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ļ”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/