Auto add request to cart option
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi All,
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @v-paulp !!
This requirement must be handled server-side using a Flow or Business Rule with the Cart API.
Solution Approach:-
1) Client-side (optional validation)
Use a Catalog Client Script (onSubmit) only to read values (do not add items here).
2)Server-side (Main logic – Recommended)
Create an After Insert Business Rule on sc_req_item
(or Flow triggered on RITM creation)
Condition:
Environment = env1
Selected combination is NOT:
pro11 – role111
pro12 – role121
(function executeRule(current, previous) {
// Prevent recursion
if (current.u_auto_created == true) {
return;
}
var env = current.variables.environment;
var project = current.variables.project;
var role = current.variables.role;
if (env == 'env1' &&
!((project == 'pro11' && role == 'role111') ||
(project == 'pro12' && role == 'role121'))) {
var cart = new Cart();
// First required combination
cart.addItem('CATALOG_ITEM_SYS_ID', {
environment: 'env1',
project: 'pro11',
role: 'role111',
u_auto_created: true
});
// Second required combination
cart.addItem('CATALOG_ITEM_SYS_ID', {
environment: 'env1',
project: 'pro12',
role: 'role121',
u_auto_created: true
});
cart.placeOrder();
}
})(current, previous);
Why this works
Client scripts cannot add multiple requests
Cart API ensures clean request creation
Works for Portal, UI, and integrations
Recursion is avoided using a flag field
Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.
Regards,
Vaishnavi
Associate Technical Consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
what do you mean by add 2 Requests to cart?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Two requests must be automatically added to the cart, populated with the following variable values:
- Environment: env1, Project: pro11, Role: role111
- Environment: env1, Project: pro12, Role: role121
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I will suggest let your flow or workflow on your current catalog item handle the new REQ/RITM creation based on variable value
If you are using flow then you can use "Submit Catalog Item Request" flow action
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
