How to Lock down RITM/TASK Variables after Item approval?

josh_tessaro
Giga Expert

We have a requirement to lock down variables on RITM and TASK records after the record has been approved so that the values cannot be changed post approval. Preferably we would be able to lock down only variables with a value (.value != '')

This needs to be for ALL RITM and TASK record post approval so we would rather not have to write UI policy for each item type.

Ideas?

2 REPLIES 2

erik_brostrom
Mega Guru

Give this a try:



Client Script


OnLoad


sc_req_item



function onLoad() {


  //Type appropriate comment here, and begin script below


  var ap = g_form.getValue('approval');


  if(ap == 'approved'){


  var fields = g_form.elements;


  var fieldcount = fields.length;


  var val = '';


        for (var i = 0; i < fieldcount; i++){


            val = g_form.getValue(fields[i].fieldName);


            g_form.setReadOnly("variables."+fields[i].fieldName, true);


        }


  }


}


That's pretty brute force, since you're just trying out all the fields. The way I do it is by using a display business rule to tell the client which fields to make read only:



function onDisplay(current, g_scratchpad) {


      //This function will be automatically called when this rule is processed.


      var keys = [];



      for(var key in current.variables) {


              keys.push(key);


      }



      g_scratchpad.variable_names = keys;


}



Then on the client I make them read only using a UI policy:



function onCondition() {


      g_scratchpad.variable_names.forEach(function(v) {


              var field_name = "variables." + v;              


              g_form.setReadOnly(field_name, true);


      })


}