需求:通过执行计划调用生产订单的反审核至计划操作
原代码:
List<KeyValuePair<object, object>> keyValuePairList = new List<KeyValuePair<object, object>>();
keyValuePair = new KeyValuePair<object, object>("100923", "101227");
keyValuePairList.Add(keyValuePair);
if (keyValuePairList.Any())
{
var keys = new List<object>();
foreach (var k in keyValuePairList)
{
keys.Add(k.Key);
}
object[] ids = keys.ToArray();
FormOperation formOperation = meta.BusinessInfo.GetForm().GetOperation("UndoToPlan");
SetStatus setStatus = new SetStatus(ctx);
setStatus.Initialize(meta.BusinessInfo, formOperation.Operation, OperateOption.Create());
setStatus.PkEntryIds = keyValuePairList;
IOperationResult result = setStatus.Excute(ids);
}
问题:执行计划执行出错
错误原因:从额外选项OperateOption中获取变量失败,变量[_BillOperationSelectedRows_]不存在!
解决方案:反执行至计划需要用以下代码处理:
List<long> autoMoEntryIds = new List<long>() { 101227 };
ListSelectedRowCollection srcRows = new ListSelectedRowCollection();
ListSelectedRow row = new ListSelectedRow(
Convert.ToString(100923),//生产订单内码
Convert.ToString(101227),//生产订单分录内码
1,//生产订单行号
"PRD_MO");//生产订单FormId
srcRows.Add(row);
OperateOption option = OperateOption.Create();
option.SetVariableValue("_BillOperationSelectedRows_", srcRows);
IOperationResult result = AppServiceContext.PRDService.MOService.MOStateTransfer(
this.Context, autoMoEntryIds.Distinct(), "UndoToPlanConfirm", option);
推荐阅读