Variable editor not showing on dynamic request items

kchorny
Tera Guru

I have a catalog item, let's call it 'Request a network', where the user fills out a multi-row variable set (MRVS). Then the flow designer flow creates a request item (Catalog item = New connection) for each row in the MRVS. All that is working fine, the RITMs get created, but the Variables section is not visible on them at all.

 

When I view the form layout, I see Variable editor listed. I have several variables in this catalog item, so I'm stumped. I have checked for UI policies and client scripts running on the sc_req_item table and found nothing that would cause this. Nor are there any catalog UI policies or catalog client scripts for this catalog item. And even if there were, they wouldn't hide the entire Variable editor.

1 ACCEPTED SOLUTION

kchorny
Tera Guru

I figured this out. In my flow designer flow, I was using the OOB 'Create record' action to create the RITM records. I had to change my strategy and use a custom action with a script step that creates the RITMs using the following lines:

var helper = new GlideappCalculationHelper();
helper.addItemToExistingRequest(parentRequest,catItem,1);
helper.rebalanceRequest(parentRequest);

 

Where parentRequest and catItem are values that are passed into the custom action. When passing in parentRequest, the action input is a string and should be the related Request's sys_id.

View solution in original post

17 REPLIES 17

Thank you, the variable editor is on the form, and variables display properly in RITMs created using standard methods.

 

I tried setting the variables to global=true but that didn't solve the problem.

kchorny
Tera Guru

I figured this out. In my flow designer flow, I was using the OOB 'Create record' action to create the RITM records. I had to change my strategy and use a custom action with a script step that creates the RITMs using the following lines:

var helper = new GlideappCalculationHelper();
helper.addItemToExistingRequest(parentRequest,catItem,1);
helper.rebalanceRequest(parentRequest);

 

Where parentRequest and catItem are values that are passed into the custom action. When passing in parentRequest, the action input is a string and should be the related Request's sys_id.

Aayush5
Tera Contributor

Hey @kchorny i have the similar requirement, so can you please share your custom code here ?

 

Here is contents of the script step in my custom action. I am creating a separate RITM for each row in a MRVS.

 

You can see which inputs and outputs I had to create wherever I used inputs.[input variable] and outputs.[output variable]. 

 

Hope this helps!

 

(function execute(inputs, outputs) {
var parentRitm = new GlideRecord('sc_req_item');
parentRitm.get(inputs.ritm_id);
var connections = parentRitm.variables.add_connections_on_existing_network; //this is the MRVS where I am creating a new RITM for each row in the MRVS
var json = JSON.parse(connections);
var catItem = '245f5e8c1bed2510fbbbeaccac4bcbfa'; //Add connection
var parentRequest = inputs.request_id;
var rowNumber = inputs.row;
rowNumber = rowNumber.toString();
var newRitmNumber = '';

//create a Add Connection RITM
var helper = new GlideappCalculationHelper();
helper.addItemToExistingRequest(parentRequest,catItem,1);
helper.rebalanceRequest(parentRequest);

//find the RITM that was just created and copy the variables over
var i = new GlideRecord('sc_req_item');
i.addQuery('request',parentRequest);
i.addQuery('cat_item',catItem);
i.orderByDesc('sys_created_on'); //get the last one created
i.query();
if (i.next()) {
gs.log('RITM found: ' + i.number,"KC");
i.due_date = inputs.due_date;
newRitmNumber = i.number;
i.variables.var_row_number = rowNumber;
i.variables.var_sap_number = inputs.sap_number;
//copy the user information variables
i.variables.user_name = parentRitm.variables.user_name;
i.variables.department = parentRitm.variables.department;
i.variables.phone_number = parentRitm.variables.phone_number;
i.variables.room_number = parentRitm.variables.room_number;
i.variables.title_position = parentRitm.variables.title_position;
i.variables.last_name = parentRitm.variables.last_name;
i.variables.first_name = parentRitm.variables.first_name;
i.variables.user_email = parentRitm.variables.user_email;

//copy the requested connection variables to the Update Faceplate Info variables
for (var m=0;m<json.length;m++) {
if (json[m].mrvs_1_row_number == rowNumber) {

i.variables.var_room_not_found = json[m].mrvs_1_room_not_found;
i.variables.var_faceplate_install_needed = json[m].mrvs_1_faceplate_install_needed;
i.description = 'New connection ritm created via parent ritm flow for requested connection row number: ' + rowNumber;

if (json[m].mrvs_1_need_phone == 'Yes') {
i.variables.var_need_phone = 'True';
i.variables.var_whose_phone = json[m].mrvs_1_whose_phone;
i.variables.var_extension = json[m].mrvs_1_phone_extension;
}
if (json[m].mrvs_1_enter_room)
i.variables.var_room_name = json[m].mrvs_1_enter_room;
if (json[m].mrvs_1_select_faceplate)
i.variables.var_selected_faceplate = json[m].mrvs_1_select_faceplate;
if (json[m].mrvs_1_select_jack)
i.variables.var_selected_jack = json[m].mrvs_1_select_jack;
if (json[m].mrvs_1_select_room)
i.variables.vs_select_room = json[m].mrvs_1_select_room;
if (json[m].mrvs_1_enter_faceplate)
i.variables.var_manually_entered_faceplate = json[m].mrvs_1_enter_faceplate;
if (json[m].mrvs_1_enter_jack_number)
i.variables.var_manually_entered_jack = json[m].mrvs_1_enter_jack_number;
if (json[m].mrvs_1_which_network)
i.variables.var_network = json[m].mrvs_1_which_network;
if (json[m].mrvs_1_network_name)
i.variables.var_network_name = json[m].mrvs_1_network_name;
}
}
i.update();
}
else
newRitmNumber = 'No RITM created';

outputs.new_ritm_number = newRitmNumber;


})(inputs, outputs);

 

 

Aayush5
Tera Contributor

Thanks for the replay, but I have achieve this in a more simple way.

Here is the code for reference:

The input and output variables are mentioned in code comment.

 

 

 

(function execute(inputs, outputs) {
  var mrvs = inputs.mrvs;   // input as array.object type
  var req = inputs.ritm;    // string type input
  var review = inputs.review_type; // string type input
  var report = inputs.report;  // string type input
  var month = new GlideDateTime().getMonth();
  var shortdesc = "UAR - " + report + " - " + review + " - " + month;
 
  // Insert new requested item record for each row of mrvs
  var childRITM = new GlideRecord("sc_req_item");
  childRITM.initialize();
  childRITM.setValue("cat_item",'475824a91b512914243c20a5604bcb33'); // Request a User Access Review Catalog item
  childRITM.setValue("short_description", shortdesc);
  childRITM.setValue("approval", "approved");
  var childRITMsysId = childRITM.insert();
  
  // Update RITM to set request , requested for and opened by
  var updateRITM = new GlideRecord("sc_req_item");
  updateRITM.addQuery('sys_id', childRITMsysId);
  updateRITM.query();
  if(updateRITM.next()){
    updateRITM.setValue("request",req);
    updateRITM.setValue("opened_by", req.opened_by);
    updateRITM.setValue("due_date", req.opened_at);
  	updateRITM.setValue("requested_for", req.requested_for);
    updateRITM.update();
    
    // Insert variable record for newly created ritm in variable ownership table
    var variablesForRitm = ['u_review_type','mrvs_uar_system','mrvs_uar_report','mrvs_uar_pre','mrvs_uar_review','mrvs_uar_post','attachment'];
    var grTaskVariable = new GlideRecord('sc_item_option_mtom');
    var grVariableM2M = new GlideRecord('sc_item_option_mtom');
    grVariableM2M.addQuery('request_item', inputs.ritm_sysid);
    grVariableM2M.addQuery('sc_item_option.item_option_new.name', 'IN', variablesForRitm.join(','));
    grVariableM2M.query();
    while (grVariableM2M.next()) {
        grTaskVariable.initialize();
        grTaskVariable.setValue('request_item', childRITMsysId);
        grTaskVariable.setValue('sc_item_option', grVariableM2M.sc_item_option);
        grTaskVariable.insert();
    }
    
    // Insert MRVS record for newly created ritm in Multi Row Question Answer table
    var mrvsForRitm = ['mrvs_uar_system','mrvs_uar_report','mrvs_uar_pre','mrvs_uar_review','mrvs_uar_post'];
    var grTaskMrvs = new GlideRecord('sc_multi_row_question_answer');
    var grParentMrvs = new GlideRecord('sc_multi_row_question_answer');
    grParentMrvs.addQuery('parent_id', inputs.ritm_sysid);
    grParentMrvs.addQuery('sc_item_option.item_option_new.name', 'IN', mrvsForRitm.join(','));
    grParentMrvs.query();
    while (grParentMrvs.next()) { 
      grTaskMrvs.initialize();
      grTaskMrvs.setValue('parent_id', childRITMsysId);
      grTaskMrvs.setValue('sc_item_option', grParentMrvs.sc_item_option);
      grTaskMrvs.setValue('item_option_new', grParentMrvs.item_option_new);
      grTaskMrvs.setValue('parent_table_name', grParentMrvs.parent_table_name);
      grTaskMrvs.setValue('value', grParentMrvs.value);
      grTaskMrvs.setValue('variable_set', grParentMrvs.variable_set);
      grTaskMrvs.setValue('row_index', grParentMrvs.row_index);
      grTaskMrvs.insert();
    }
  }
  outputs.ritm_record = childRITMsysId;  // output as string 
  
})(inputs, outputs);

 

 

 

Make as Helpful if you found it!

 

Thanks!