执行计划创建基础资料时报错
需求:
通过执行计划创建仓库,代码参考此贴:https://wenku.my7c.com/article/24828?productLineId=1
问题:
执行计划自动执行或者通过Administrator执行时报错,报错信息如下:您要读取的数据在系统中不存在,可能已经被删除![ID=-1,Type=Organization]
出现原因:
Context获取到的组织ID是-1,程序无法识别
解决方法:
赋值Context的CurrentOrganizationInfo,获取方法如下:
/// <summary>
/// 获取指定组织的OrganizationInfo
/// </summary>
/// <param name="ctx">上下文</param>
/// <param name="mainNumber">需要获取OrganizationInfo的组织编码</param>
/// <returns></returns>
public static OrganizationInfo GetOrganizationInfo(Context ctx, string mainNumber)
{
FormMetadata orgMetadata = FormMetaDataCache.GetCachedFormMetaData(ctx, "ORG_Organizations");
var queryParam = new QueryBuilderParemeter()
{
FormId = "ORG_Organizations",
FilterClauseWihtKey = string.Format("FNumber = '{0}' ", mainNumber),
};
var orgObj = BusinessDataServiceHelper.LoadFromCache(ctx,orgMetadata.BusinessInfo.GetDynamicObjectType(), queryParam).FirstOrDefault();
//创建组织
var organizationInfo = new OrganizationInfo()
{
FunctionIds = Convert.ToString(orgObj["OrgFunctions"]).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(p => !string.IsNullOrWhiteSpace(p)).Select(o => Convert.ToInt64(o)).ToList(),
ID = Convert.ToInt64(orgObj["Id"]),
Name = Convert.ToString(orgObj["Name"]),
};
return organizationInfo;
}
执行计划创建基础资料时报错
本文2024-09-16 18:31:09发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22666.html