Copying RITM variables into Catalog Item variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2016 10:12 AM
This may seem like a strange customization, but we've had a request to be able to copy an RITM, similar to copying a Change request. With the Change, the fields are copied over but then the client would make all of the necessary modifications and then submit. From an RITM perspective, the only way that I can picture being able to do the same thing is by having the UI Action pull the Item Name, go to the catalog item form, and copy all of the variables into that form so that the client can modify and then submit a request.
I have never seen anything like this before, but I think the logic is sound, but technically I'm not sure if it can be done.
Any ideas on how this might be able to function?
Thanks in advance!
Amandah

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2016 10:55 AM
Hi Amandah,
Forgive me for copying a bit of text from my other posts, but here is a quick summary of how variables/RITMS/Tasks/etc. are all related from the table perspective. Once you understand that, it can make it easier to do what you need to do.
-----------
Here is how they are related from Variable definition all the way to the values on your RITM/CTASK.
Here is a rundown of the tables involved:
- [sc_cat_item] holds the definitions for your Catalog Items
- [item_option_new] holds definitions of variables
- [item_option_new_set] holds definitions of variable sets
- [io_set_item] is a many-to-many table relating Variable Sets to Catalog items
- [sc_cart] contains the shopping cart for users
- [sc_cart_item] contains the items a user has placed in the cart
- [sc_item_option] contains the values a user has entered for the variables associated to the items in the cart
- [sc_item_option_mtom] is a many-to-many table relating these variable values to their respective Requested Items
- [sc_item_variables_task] is a many-to-many table relating these same variables to their respective Catalog Tasks (if one gets created)
- [sc_req_item] contains the Requested Items
- [sc_task] contains the Catalog Tasks
When an item is being ordered, the system polls the Cat.Item for all variable sets and variables that belong to it, presenting the questions to be answered and storing answers in [item_option_new] for access by the Requested Item that gets created when the order is completed. If a RITM also creates a Catalog Task, then entries will also be added to [sc_item_variables_task] for that task and the variable values.
-----------
To grab all the variables for a particular RITM, you will want to look at the table [sc_item_option_mtom]. To do this from the client side, I would suggest writing an AJAX utility of some kind to compile all the variables.
That being said, from the existing RITM I would give them a UI Action that will call the AJAX utility:
- Pass the current RITM's sys_id and cat_item in your AJAX call
- Have the AJAX utility compile the variable names and values from said RITM (using [sc_item_option_mtom] and [sc_item_option] to do so).
- Pass these back in the AJAX result/message to your form, which can then redirect to your Catalog Item while providing the variable values as sysparms.
Here's a brief wiki on using GlideAjax, but you can find a lot more on using it just by browsing the Script Includes for ones containing 'AJAX' in the name and look to see how they are contructed/used:
See how that works out for you.
Thanks,
-Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2016 11:23 AM
It looks like you want to clone an existing request item and create a new one. I have done something like this where I have to clone an existing request item and create other request item in the same request. You can modify this code to fit your requirement. I hope this helps :-
Its an After Insert business rule on sc_request table
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var count = 0;
var gr = new GlideRecord('u_bundle_item_catalog');
gr.addQuery('u_active', true);
gr.addQuery('u_bundle', '!=', '');
gr.query();
while (gr.next()) {
var list = gr.u_bundle.toString();
var array = list.split(",");
var reqitem = new GlideRecord('sc_req_item');
reqitem.addQuery('request', current.sys_id);
reqitem.addQuery('cat_item', '66f666a14f6746006dbd926ca310c7ce'); //Sys iD of New Hire Instrauction Item
reqitem.query();
if(reqitem.next()) {
for (var i=0; i < array.length; i++) {
if(reqitem.variables.bundle == array[i]) {
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.sys_id,'0d29a6084fd742006dbd926ca310c770','1'); // Sysid of Hardware Item and 1 is the qty
reqHelper.rebalanceRequest(current.sys_id);
//update variables
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.sys_id);
grReqItem.addQuery('cat_item','0d29a6084fd742006dbd926ca310c770');
grReqItem.query();
while (grReqItem.next()) {
if(grReqItem.variables.sub_category == '') {
grReqItem.variables.sub_category = gr.u_subcategory;
}
if(grReqItem.variables.item_name == '') {
grReqItem.variables.item_name = gr.u_item_name;
}
grReqItem.variables.desk_number = "NA as New Hire";
grReqItem.variables.computer_name = "NA as New Hire";
grReqItem.variables.reason = "new_hire";
grReqItem.variables.short_description = "Created as part of Bundle: " +array[i];
grReqItem.variables.details = "Created as part of Bundle: " +array[i];
grReqItem.short_description = "Created as part of Bundle: " +array[i];
grReqItem.description = "Created as part of Bundle: " +array[i];
grReqItem.variables.employee_name = reqitem.variables.employee_name;
grReqItem.variables.employee_start_date = reqitem.variables.employee_start_date;
grReqItem.variables.employee_type = reqitem.variables.employee_type;
grReqItem.variables.department = reqitem.variables.department;
grReqItem.variables.cost_center = reqitem.variables.cost_center;
grReqItem.variables.address = reqitem.variables.address;
grReqItem.update();
}
}
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2016 09:24 AM
Hello there,
I needed the same 'copy' function to occur on a Task. Here is the script used to copy all the custom variables from the record producer onto a new task. The part in bold text might be of the most use. I hope this answers your question. If not, please let me know so I can further assist.
var task = new GlideRecord ("u_marketing_requests");
task.u_requestor = current.u_requestor;
task.short_description = current.short_description;
task.assignment_group = current.assignment_group;
task.work_notes = current.work_notes.getJournalEntry(-1); // -1 will get all journal entries as a string
task.comments = current.comments.getJournalEntry(-1);
/*task.var_requestor = producer.var_requestor;
task.getXML(populateHistory);*/
var sysID = task.insert();
var gr = new GlideRecord('question_answer');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
while(gr.next()){
var tableName= gr.table_name;
var order = gr.order;
var question = gr.question;
var value = gr.value;
var grt = new GlideRecord('question_answer');
grt.initialize();
grt.table_name = tableName;
grt.order = order;
grt.question = question;
grt.value = value;
grt.table_sys_id = sysID;
grt.insert();
}
//provide onscreen feedback and set URLs
gs.addInfoMessage("Marketing Task " + task.number + " created");
action.setRedirectURL(task);
action.setReturnURL(current);