Make a variable mandatory on a single catalog task based on some other variable's value.
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 08:48 AM
Hi,
I have a catalog item where there are two fields - ID and Is approval required(yes/no). The id field is not visible on the form , it will be visible on catalog tasks. In the workflow there are 4 catalog tasks which are generated.
I want that when 'is approval required' is yes, ID should be mandatory on task 1. Similarly when 'is approval required' is No, ID should be mandatory on task 2.
Can someone help me on how to achieve this?
 
					
				
		
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 09:05 AM
Based upon what you describe, I am guessing that you want to have specific variables become mandatory only on a particular task, and only when the record becomes closed. If this is true, we can use a UI Policy on the Catalog Task table (not a Catalog UI Policy) to achieve this. I have done this before, so if this is the case and you want more information, let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2019 11:04 PM
Yes, can you please help with more information regarding this?
Specifically, how to make it mandatory on a single task according to the value of a variable.
 
					
				
		
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2019 08:43 AM
There is a hidden field on the Catalog Task record called Workflow activity [wf_activity]. This field can be leveraged to identify what Specific task we are making the variable mandatory for. If you look at your workflow, you will see what name this is looking at. For our example, I am using Task 1 and Task 2 as the names of the Catalog Task workflow activities. If your task names are different, be sure to use those. Also, I am using approval_required and id as the variable names, if the variable names are different, be sure to use those.
1. Create a Business rule that captures the wf_activity name:
 Name: Set g_scratchpad for sc_task
 Table: Catalog Task [sc_task]
 Advanced: true
 When: Display
 Script:
(function executeRule(current, previous /*null when async*/) {
    g_scratchpad.wf_activity = current.wf_activity.getDisplayValue();
})(current, previous);2. Create a UI Policy on the Catalog Task table that makes the variable mandatory when closing:
- Make Variables Mandatory on Close
 Table: Catalog Task [sc_task]
 Reverse if false: true
 Order: 300
 Global: true
 Short description: Make Variables Mandatory on Close
 Conditions:
 State | is | Closed Complete
 Run scripts: true
 Execute if True:
function onCondition() {
    if (g_scratchpad.wf_activity == 'Task 1') {
        if (g_form.getValue('variables.approval_required') == 'Yes') {
            g_form.setMandatory('variables.id', true);
        }
    }
    if (g_scratchpad.wf_activity == 'Task 2') {
        if (g_form.getValue('variables.approval_required') == 'No') {
            g_form.setMandatory('variables.id', true);
        }
    }
}Execute if False:
function onCondition() {
    g_form.setMandatory('variables.id', false);
}3. Change the existing UI Action used to close the task to include the logic to make the variable mandatory:
Close Task
 Name: Close Task
 Table: Catalog Task [sc_task]
 Order: 100
 Action name: close_task
 Client: true
 Onclick: closeTaskCheck();
 Script:
function closeTaskCheck() {
    if (g_scratchpad.wf_activity == 'Task 1') {
        if (g_form.getValue('variables.approval_required') == 'Yes') {
            g_form.setMandatory('variables.id', true);
        }
    }
    if (g_scratchpad.wf_activity == 'Task 2') {
        if (g_form.getValue('variables.approval_required') == 'No') {
            g_form.setMandatory('variables.id', true);
        }
    }
    gsftSubmit(null, g_form.getFormElement(), 'close_task');
}
if (typeof window == 'undefined') serverCloseTask();
function serverCloseTask() {
    current.state = 3;
    current.update();
}Let us know if you have any difficulty, or questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2019 10:51 AM
Hi , Thanks for your reply.
However I am facing a difficulty that, in the first catalog task, there are a few variables visible(which were hidden on catalog item form) and according to their values, different catalog tasks are generated.
So I do not know for sure that which will be the second task generated.
I want to make the variable mandatory on second task(whichever generated) if value of variable "approval required" is 'no' on the first catalog task.
