Add catalog items to Order guide dynamically using script (without rule base)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2017 08:11 AM
Hi, i was searching for this solution in community but couldn't find. I decided to build the solution by my own. here I'm sharing it.
Requirement: This requirement is for new joiner order guide setup. the client come up with list of catalog items and list of job roles. Initially the list is small, it may grow big may be in hundreds later stage. so, we should setup describe needs form to select the requested for user, populate relevant job roles to that user. based on job role(s) selected specific items should be available on choose options form.
Initially it looks easy, but later it took some time to implement it.
Solution:
1) I created a Job role custom table to hold the list of all job roles.
2)Created a custom mapping table between job role and catalog items
3) Created a custom variable on sc_cart table (I named it current guide variables)
4)on describe needs form, added requested for user, Job role(s) list collector
5) Created on Submit script to pass 'Job role' sys ids to my custom field on sc_cart using synchronous glide Ajax call
6)created script on order guide form to get the job roles selected from the cart, based on these values, got the catalog items mapped from my custom mapping table between job role and catalog items.
7)Added them using guide.add() function. So, no rule base is required.
----------------------------------------------------------
addItems();
function addItems(){
var cart = new GlideRecord('sc_cart');
cart.addQuery('user',gs.getUserID());
cart.query();
if(cart.next()){
var jrSysIDs = cart.u_current_guide_variables.toString();
var arrSysIDs = [];
var arrUtil = new ArrayUtil();
var item = new GlideRecord('u_m2m_job_role_cat_item');
item.addQuery('u_active',true);
item.addQuery('u_job_role','IN',jrSysIDs);
item.addQuery('u_order_guide',cart.current_guide);
item.query();
while(item.next()){
var temp_sysID = item.u_catalog_item.toString();
//get catalog items sysid, exclude duplicates
if(!arrUtil.contains(arrSysIDs,temp_sysID)){
arrSysIDs.push(temp_sysID);
}
}
gs.log(arrSysIDs);
//Add items to guide
for(var i=0;i<arrSysIDs.length;i++){
guide.add(arrSysIDs[i]);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 12:45 AM
Hi Prakash,
I had a similar type of requirement to manage the software model suite in Service Management.
Could you please explain the steps involved in adding the catalog item without rule base in order guide.
Thanks,
Ram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2019 10:46 AM
Does this work in the portal?
Thank you!