Making variables mandatory on RITM when a certain task is created

turnea
Mega Expert

Hi everyone,

I have a fairly complex process for building servers where the engineer actually fills in variables from the RITM level.   The requirement is for certain fields that are not visible during the client filling out the form to be mandatory when the IT engineer receives their task.   There is an approval that needs to be done prior to the IT Engineer receiving the task to make the changes, so I can't simply use a UI policy from the beginning.   Has anyone ever done some form of script that will make variables mandatory on the RITM level *only* when a specific task is created?   I'm pretty stuck here right now.

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

You should be able to do a catalog client script of a catalog ui policy that does this, you just need to define your trigger.   You can make mandatory once the request is approved:


onLoad


var approval = g_form.getReference('request').approval;


if(approval == 'Approved'){


g_form.setMandatory('field', true);


}else{


g_form.setReadOnly('field', true);


}


View solution in original post

5 REPLIES 5

Mike Allen
Mega Sage

You should be able to do a catalog client script of a catalog ui policy that does this, you just need to define your trigger.   You can make mandatory once the request is approved:


onLoad


var approval = g_form.getReference('request').approval;


if(approval == 'Approved'){


g_form.setMandatory('field', true);


}else{


g_form.setReadOnly('field', true);


}


Okay, I'll see what I can do with the script on the RITM level and see what happens.


Hi Mike,



I tried using your script and it set the variable to read only, even though it should have been mandatory, meaning the query didn't work.   I'm looking for it showing as approved on the RITM level, not the REQ level.   Is that the getReference you're using?   For me, it looks like it might be the REQ level.   I tried this and it didn't work either - any thoughts?



function onLoad() {


  var ritm = new GlideRecord("sc_req_item");


  var approval = ritm.approval;


  if(approval == 'Approved'){


  g_form.setMandatory('Server_Name', true);


  }



}


Maybe it was the upper case A in approval.   This worked for me:



Capture.PNG