Updating one RITM updates all RITM's on the REQ

jsummers
Kilo Contributor

Trying to set it up so that if someone updates a variable that is shared between RITM's (as in, shares the same name), it will update all of the variables, on all of the RITM's, of that REQ. The example would be for on-boarding where we have an Order Guide that creates the REQ using Catalog Items and variable sets. If the variable Employee Start Date (emp_start) needs to be updated, HR only has to update it on one Catalog Item and then it could replicate to all of them.

 

I'm hoping someone has already accomplished this but can't seem to find a discussion. If they haven't, would this be best through a Business Rule that would run through all of the RITM's via the REQ?

 

Any help would be greatly appreciated.

-Jon

1 ACCEPTED SOLUTION

unigrpmm
Giga Contributor

Jon --   I wrote a script yesterday that got this to work.  


Table:   sc_req_item


When:   After, Update


Condition:     current.variable_pool.changes()



updatePeerItems();


function updatePeerItems() {



var req = new GlideRecord('sc_request')  


if (req.get(current.request)){  


          req.description = current_description;  


          req.update();  


    }  




    var gr = new GlideRecord("sc_req_item");


    gr.addQuery("request", current.request);


    gr.query();


    while (gr.next()) {  


// names of common variables all start with common...


gr.variable_pool.common_LN = current.variable_pool.common_LN;


gr.variable_pool.common_MI = current.variable_pool.common_MI;


gr.variable_pool.common_FN = current.variable_pool.common_FN;


gr.variable_pool.common_preferred_name = current.variable_pool.common_preferred_name;


gr.update();


}  


}


View solution in original post

10 REPLIES 10

Here's a code snippet where I'm copying a list of all variables into a text variable ( named lov ).


You can adapt this for your needs.   This snippet comes from a UI Action to create a change request from a requested item.


You'll probably want to replace all the code in the loop "for ( x = 0; x<sorted.length; x++) " with code for what you want to do.



-------------------------------- Begin code snippet -------------------------------


var lov     = "\n===== List of Variables from Requested Item (" + current.number + ") =====";



var index = 0;


var array = [];


for (var prop in current.variables )


{


      array[index] = prop;


      index++;


}



var sorted = array.sort();



for ( x = 0; x<sorted.length; x++)


{


      var key = sorted[x];


      var value = current.variables[key].getDisplayValue();


      var line = "\n-> variable " + key + " = " + value;


      if ( /\n/m.test(value) )


      {


              line = "\n-> variable " + key + " (multi-line) follows: --\n" + value + "\n<--- end of multi line variable " + key + " ---";


      }


      lov = lov + line;


}



change.description = "From " + current.number + ": " + current.short_description + "\n" + current.description + lov;


-------------------------------- End code snippet -------------------------------