Make variables mandatory during approval

Vengeful
Mega Sage

I have a requirement that make variables mandatory during approval.

When Approval is Requested

Vengeful_0-1721291807436.png

These variables should be mandatory before the approver can approve the request.

Vengeful_1-1721291947829.png

 

How to achieve that?

5 REPLIES 5

Trupti94
Tera Guru

Hi @Vengeful ,

 

you can create ui policy which will work on RITM only to make these variables mandatory when approval is requested.

 

Trupti94_0-1721293104843.png

 

This would not work as I assume the approver will be interacting with the Approval (sysapproval_approver), not the RITM when approving the RITM, so the UI Policy would not apply.

 

There isn't a quick, neat way to do this if the approver is not interacting directly with the RITM when they are approving it. If you only need to cater for this requirement for this specific Catalog Item then you could add a Business Rule to the sysapprover_approval table with something similar to the below:

 

Trigger condition:

[State][changes to][Approved][AND]

[Approval for.Class][is][sc_req_item][AND]

[Approval for.[Requested Item]Item][is][INSERT CATALOG ITEM HERE]

 

Order = 1000

When = Before

Update = True

Insert = False

 

Code:

var grRITM = current.approval_for.getRefRecord();
if(grRITM.isValidRecord()){
	var variableNames = ['INSERT_VARIABLE_NAME_1','INSERT_VARIABLE_NAME_2','INSERT_VARIABLE_NAME_3']; // Stores the names of the Variables that are required to be populated prior to approval
	var emptyVariables = []; // Stores the labels of the Variables that are found to be unpopulated
	var message = ['Please add values to the following Variables on the associated RITM before approving:'];

	for(var i = 0; i < variableNames.length; i++){
		var variable = grRITM.variables[variableNames[i]];
		if(!variable){
			emptyVariables.push(variable.getLabel());
		}
	}

	if(emptyVariables){
		current.setAbortAction(true); // A Variable is unpopulated, so prevent the approval progressing
		for(var j = 0; j < emptyVariables.length; j++){
			message.push(emptyVariables[j]);
		}
		gs.addErrorMessage(message.join('\n'));
	}
}

This would also prevent approvals via email but there would be no mechanism to inform the approver the approval wasn't processed as expected. 

Community Alums
Not applicable

Hi @Vengeful ,

 

Can you please try the below code-

(function executeRule(current, previous /*null when async*/) {
    var grRITM = current.approval_for.getRefRecord();
    if(grRITM.isValidRecord()){
        var variableNames = ['variable_name_1', 'variable_name_2', 'variable_name_3']; // Replace with actual variable names
        var emptyVariables = []; // Stores the labels of the Variables that are found to be unpopulated
        var message = ['Please add values to the following Variables on the associated RITM before approving:'];

        for(var i = 0; i < variableNames.length; i++){
            var variable = grRITM.variables[variableNames[i]];
            if(variable && !variable.getValue()){
                emptyVariables.push(variable.getLabel());
            }
        }

        if(emptyVariables.length > 0){
            current.setAbortAction(true); // Prevent the approval from progressing
            for(var j = 0; j < emptyVariables.length; j++){
                message.push(emptyVariables[j]);
            }
            gs.addErrorMessage(message.join('\n'));
        }
    }
})(current, previous);

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!


Thanks & Regards,

Sanjay Kumar

Hi @Nicholas_Gann ,

 

I cannot find this condition
[Approval for.Class][is][sc_req_item][AND]