Make variables mandatory during approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 01:40 AM
I have a requirement that make variables mandatory during approval.
When Approval is Requested
These variables should be mandatory before the approver can approve the request.
How to achieve that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 01:56 AM - edited 07-18-2024 01:58 AM
Hi @Vengeful ,
you can create ui policy which will work on RITM only to make these variables mandatory when approval is requested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 03:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 06:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 05:04 PM