Fx. approval

Fx.approval: Approval related functions

1. Query the approval instance on the object (query is not real-time, there is a delay, real-time query can refer to Lexiang article: Real-time query function of approval flow)

Fx.approval.findInstances(<String objectApiName>, <List state>, <String dataId>, <Integer limit>, <Integer skip>, <ActionAttribute attribute>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| objectApiName | String | apiName of the object |
| state | List | Instance state, transfer list, empty list means all states, currently supported instance states: in_progress (in progress), pass (pass), cancel (cancel), error (abnormal), reject (reject) |
| dataId | String | Business data Id, cannot be empty |
| limit | Integer | Limit the number of queries, the maximum is 100 |
| skip | Integer | How many pieces of initial data to skip |
| attribute | ActionAttribute | optional parameters |

return type

APIResult

Return value description

Approval task list, the fields related to the returned approval task include: Data id (dataId) Creation time (createTime) Current approver list (userIds) Approval comments (opinions) Opinion writer (reply_user) Action type (action_type) Supported types are: agree (agree), reject (reject) Reply time (reply_time) Approval opinion (opinion) Object apiName (objectApiName) Approval status (state) Type (type) Approval task node ID (taskId)

Java example

APIResult retData = Fx.approval.findInstances("object_pjy2L__c", Lists.newArrayList("in_progress"), "5e9858f5865dbc000155dd87", 10, 0);
log.info(retData);

Groovy example

def retData = Fx.approval.findInstances("object_pjy2L__c", ["in_progress"], "5e9858f5865dbc000155dd87", 10, 0)
log. info(retData)

2. Query the approval instance on the object

Fx.approval.findInstances(<String objectApiName>, <Integer limit>, <Integer skip>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ---------------------------------------- |
| objectApiName | String | apiName of the object |
| limit | Integer | Limit the number of queries, the maximum is 100 |
| skip | Integer | How many pieces of initial data to skip |

return type

APIResult

Return value description


3. Query all task nodes of the approval instance

Fx.approval.findTasks(<String instanceId>, <ActionAttribute attribute>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| instanceId | String | The unique ID of an approval process |
| attribute | ActionAttribute | optional parameter, |

return type

APIResult

Return value description

Java example

APIResult ret = Fx.approval.findTasks("5fa89df8f791130001557774");
log. info(ret);

Groovy example

def ret = Fx.approval.findTasks("5fa89df8f791130001557774")
log. info(ret)

4. Withdraw Approval

Fx.approval.cancelApproval(<String objectApiName>, <String dataId>, <String comment>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| objectApiName | String | apiName of the object |
| dataId | String | business data Id |
| comment | String | Approval comments |

return type

APIResult

Return value description

Java example

APIResult ret = Fx.approval.cancelApproval("object_pjy2L__c", "5e9858f5865dbc000155dd87", "Cancel");
log. info(ret);

Groovy example

def ret = Fx.approval.cancelApproval("object_pjy2L__c", "5e9858f5865dbc000155dd87", "Cancel")
log. info(ret)

5. Operate the approval task node

Fx.approval.approvalAction(<String taskId>, <String actionType>, <String opinion>, <String userId>, <String apiName>, <String dataId>, <Map data>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| taskId | String | Approval task node Id |
| actionType | String | Operation type, the supported types are agree (agree), reject (reject) |
| opinion | String | Approval opinion |
| userId | String | Approver Id |
| apiName | String | optional parameter, object apiName |
| dataId | String | optional parameter, data id |
| data | Map | optional parameter, field information needs to be updated when the approval flow collaboration task is completed, |

return type

APIResult

Return value description

taskId : the taskId of the successful operation

Java example

APIResult ret = Fx.approval.approvalAction("5fa89df8f791130001557775", "agree", "agree", "1027");
log. info(ret);

Groovy example

def ret = Fx.approval.approvalAction("5fa89df8f791130001557775", "agree", "agree", "1027")
log. info(ret)

6. Change the approver of the approval task node

Fx.approval.setApprovalIds(<String taskId>, <List userList>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| taskId | String | Approval task node Id |
| userList | List | Approver List |

return type

APIResult

Return value description

Java example

APIResult ret = Fx.approval.setApprovalIds("5fa8a1c2f791130001557776", Lists.newArrayList("1007", "1017"));
log. info(ret);

Groovy example

log. info(ret)

7. Query the task node information that can be dismissed through the current instance

Fx.approval.getCanRefuseTasks(<String instanceId>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| instanceId | String | Approval instance Id |

return type

APIResult

Return value description

Map, including the following fields: taskId: task node id taskFullName: task name

Java example

APIResult ret = Fx.approval.getCanRefuseTasks("618b44e04dfcf72fe16ea6cd");
if (ret. isError()) {
 log.info(ret.message());
} else {
 log.info(ret.getData());
}

Groovy example

def(Boolean error, List data, String errorMessage) = Fx. approval. getCanRefuseTasks("618b44e04dfcf72fe16ea6cd")
if (error) {
 log. info(errorMessage)
} else {
 log. info(data)
}

8. Any node to reject (the node before the current node)

Fx.approval.rejectToBeforeTask(<String currentTaskId>, <String rejectToTaskId>, <String userId>, <String opinion>, <Boolean moveToCurrent>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| currentTaskId | String | current task node id |
| rejectToTaskId | String | The task node id to fall back to |
| userId | String | Approver Id |
| opinion | String | Rejection opinion |
| moveToCurrent | Boolean | Optional parameter, after being rejected and passed again, whether to jump directly to the node rejected last time, or continue to follow the flow chart down, the default is false (not required)
false: after rejection Pass again, continue to go down according to the flow chart
true: pass again after rejection, directly jump to the node rejected last time |

return type

APIResult

Return value description

Java example

APIResult ret = Fx.approval.rejectToBeforeTask("618b73c84dfcf72fe16ea79e", "618b7212abb2092507a2208b", "1017", "Rejection");
if (ret. isError()) {
 log.info(ret.message());
} else {
 log.info(ret.getData());
}

Groovy example

def(Boolean error, Map data, String errorMessage) = Fx.approval.rejectToBeforeTask("618b73c84dfcf72fe16ea79e", "618b7212abb2092507a2208b", "1017", "Rejection")
if (error) {
 log. info(errorMessage)
} else {
 log. info(data)
}

9. Support the whole process event configuration, complete the task, and skip the verification and post-action execution

Fx.approval.skipValidateAndCompleteTask(<String taskId>, <String opinion>, <String userId>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| taskId | String | taskId |
| opinion | String | Approval opinion |
| userId | String | user id |

return type

APIResult

Return value description

Boolean whether the execution was successful

Java example

APIResult ret = Fx.approval.skipValidateAndCompleteTask("5e9858f5865dbc000155dd87", "need to skip pre-conditions and post-actions", "1000")
if (ret. isError()) {
    log.info(ret.message());
} else {
    log.info(ret.getData());
}

10. The approval flow waits for the node to execute immediately

Fx.approval.delayTaskImmediatelyExecute(<String taskId>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| taskId | String | waiting node id |

return type

APIResult

Return value description

Map

Java example

APIResult res = Fx.approval.delayTaskImmediatelyExecute("62f3217ac6fa24292be4f833");
if(res.isError() || res.message() != ""){
  log. info(res. message())
}else{
  log.info("Approval flow automatic node is executed successfully immediately")
}

11. Whether there is an instance in the approval flow, if it exists, return the instance id

Fx.approval.existsInstance(<String entityId>, <String objectId>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| entityId | String | object ApiName |
| objectId | String | dataId |

return type

APIResult

Return value description

String Approval instance id

Java example

APIResult ret = = Fx.approval.existsInstance("AccountObj", "62e8eb7698d1f100012d6002");
if (ret. isError()) {
    log.info(ret.message());
} else {
    log.info(ret.getData());
}

Groovy example

def (Boolean error, String instanceId, String message) = Fx.approval.existsInstance("AccountObj", "62e8eb7698d1f100012d6002")
if (error) {
  log.info("error :" + message)
}
log. info(instanceId)

12. Re-parsing task handlers

Fx.approval.refreshHandler(<String taskId>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| taskId | String | task id |

return type

APIResult

Return value description

Map

Java example

String taskId = "6343e4d780f4841c79cbcae0";
APIResult ret = Fx.approval.refreshHandler(taskId);
if (ret. isError()) {
    log.info(ret.message());
} else {
    log.info(ret.getData());
}

Groovy example

def taskId = "6343e4d780f4841c79cbcae0"
def res = Fx.approval.refreshHandler(taskId)
log. info(res)

2022-11-23
0 0