1. 流程后動(dòng)作
package fx.custom.apl.example.flow;
import com.fxiaoke.functions.FunctionContext;
import com.fxiaoke.functions.Fx;
import com.fxiaoke.functions.client.DebugHelper;
import com.fxiaoke.functions.model.*;
import com.fxiaoke.functions.template.IFlowAction;
import com.fxiaoke.functions.tools.QueryOperator;
import com.fxiaoke.functions.utils.Lists;
import com.fxiaoke.functions.utils.Maps;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static com.fxiaoke.functions.Fx.log;/**
* APL函數(shù)里獲取觸發(fā)函數(shù)的主從數(shù)據(jù)
* APL函數(shù)簡(jiǎn)單操作獲取主對(duì)象數(shù)據(jù),并遍歷處理從對(duì)象數(shù)據(jù)
*/
public class FlowExample implements IFlowAction {
@Override
public void execute(FunctionContext context, Map<String, Object> map) {
// 流程后動(dòng)作函數(shù)里面的context.data數(shù)據(jù)并不會(huì)實(shí)時(shí)計(jì)算計(jì)算字段,引用字段等,也不會(huì)查相關(guān)團(tuán)隊(duì)等信息
// 建議有實(shí)時(shí)獲取計(jì)算引用字段需求的再使用FQL查詢(xún)下相關(guān)數(shù)據(jù),F(xiàn)QL里面有參數(shù)控制是否查詢(xún)相關(guān)信息
String objectId = (String) context.getData().get("_id");
String objectApiName = (String) context.getData().get("object_describe_api_name");
FQLAttribute fqlAtrr = FQLAttribute.builder()
.columns(Lists.newArrayList("_id", "name")) //需要查詢(xún)的字段
.build();
SelectAttribute selectAtrr = SelectAttribute.builder()
.needInvalid(false) //是否需要查作廢數(shù)據(jù)
.build();
//查詢(xún)主對(duì)象數(shù)據(jù)
APIResult apiResult = Fx.object.findById(objectApiName, objectId, fqlAtrr, selectAtrr);
if (apiResult.isError()) {
log.info("error:" + apiResult.getMessage());
}
log.info(apiResult.getData());
//如果有從對(duì)象數(shù)據(jù)也可以查詢(xún)從數(shù)據(jù)
QueryTemplate query = QueryTemplate.AND(
Maps.of("field_57s3W__c", QueryOperator.EQ(objectId)) //主從關(guān)系字段
);
FQLAttribute fqlAtrr2 = FQLAttribute.builder()
.queryTemplate(query)
.columns(Lists.newArrayList("_id", "name"))
.build();
APIResult apiResult1 = Fx.object.find("object_adev4__c", fqlAtrr2, selectAtrr);
if (apiResult1.isError()) {
log.info("find object_adev4__c error:" + apiResult1.getMessage());
}
if (apiResult1.isError()) {
log.info("find object_adev4__c error:" + apiResult1.getMessage());
}
log.info(apiResult1.getData());
List dataList = ((QueryResult) apiResult1.getData()).getDataList();
dataList.forEach(it -> {
log.info(it);
});
}
public static void main(String[] args) throws IOException {
//調(diào)試器
DebugHelper helper = new DebugHelper();
//調(diào)試器初始化,包括身份以及服務(wù)器的地址
//身份信息聯(lián)系A(chǔ)PL平臺(tái)獲取,具體查看application.properties配置
helper.init();
//構(gòu)造當(dāng)前執(zhí)行類(lèi)
FlowExample example = new FlowExample();
//模擬調(diào)試的上下文,例如開(kāi)發(fā)時(shí)想模擬一個(gè)客戶(hù)對(duì)象的上下文,以方便開(kāi)發(fā)
FunctionContext context = helper.context("AccountObj", "63100e7915d6a300017121cc");
//構(gòu)造被觸發(fā)時(shí)的參數(shù)
Map<String, Object> argument = Maps.newHashMap();
//執(zhí)行函數(shù)
example.execute(context, argument);
}}
2. 流程校驗(yàn)
詳見(jiàn)校驗(yàn)函數(shù)