workflow script - Set field Mandatory

brown9394
Tera Expert

Hello Experts,

Is it possible to set a field on the demand form mandatory through the workflow between tasks? Before task can be closed out, I want 'u_manager' field to be mandatory before a task can be closed. I cannot do this with a UI policy on demand form on state change, because this state has 3 different tasks, and u_manager field needs to be mandatory before the last task closed. Any ideas?

Basically after the 'confirm requested resources' task is completed, we need to set 'u_manager' mandatorybefore 'resources fulfilled' can be completed.

Screen Shot 2016-11-21 at 12.20.50 PM.png

17 REPLIES 17

jagarnathn
Tera Expert

In the run script , have this script.



var gr= new GlideRecord('sys_dictionary');


gr.addQuery('name','dmn_demand');


gr.addQuery('element','u_manager');


gr.query();


if(gr.next()){


gr.mandatory=true;


gr.update();


}




Once the last task has been closed , again run another   run script and make it false.



var gr= new GlideRecord('sys_dictionary');


gr.addQuery('name','dmn_demand');


gr.addQuery('element','u_manager');


gr.query();


if(gr.next()){


gr.mandatory=false;


gr.update();


}




Although this should work , but we should not recommend it . because we are doing it dictionary level.


Dude. What if there are multiple request submitted in one time ? Are you sure that this would work?


I would   never recommend as it is dictionary level change.


I think you will find that this solution will not work for a couple of reasons:


1) since it changes the dictionary, it changes the behavior of ALL records in the table.


2) if there are 2 workflows running at the same time, the last one that triggered will determine the behavior. This means that the field being mandatory or not has no meaning.



A better solution would be to create an additional field on the Demand table. This field is then filled by the Workflow and then you create a Data or UI Policy that listens to that field and uses it to make a field mandatory or not.


However, in your description, I also read another approach: Make sure that "Resource Fulfilled" cannot be completed before the Manager is populated (this is slightly different: you are not focusing on the manager field, but on the "Resource Fulfilled" task: you remove some choices there from the state field or you remove a UI Action, depending on the rest of your solution).



Hope it helps!


Regards, Martijn