我正在尝试为CRM 2016中的自定义实体插入状态和状态码。
这是我的代码:

if (entity.LogicalName == "activitypointer")
            {
                if (entity.Attributes.Contains("activityid") & entity.Attributes.Contains("activitytypecode"))
                {
                    entity.LogicalName = entity.Attributes["activitytypecode"].ToString();
                    entity.Id = (Guid)entity.Attributes["activityid"];

                    SetStateRequest setState = new SetStateRequest();
                    setState.EntityMoniker = entity.ToEntityReference();
                    setState.State = new OptionSetValue();
                    setState.State.Value = 2;
                    setState.Status = new OptionSetValue();
                    setState.Status.Value = 100000002;
                    SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
                }


            }


当我运行此程序时,出现异常:
100000002不是状态代码new_payState的有效状态代码。已在ID为3fbe9a4a-a733-e611-80cb-001dd8b71c1c的new_pay上完成。

当我尝试将statuscode更改为其他值2,3或其他值时,我遇到了相同的异常。如何找到该实体的有效代码状态列表?

谢谢!

最佳答案

如果您有权访问数据库,则可以通过此查询确定可能的状态/状态组合。

select state, status, isdefault
from statusmap
where objecttypecode = 4200 --activitypointer


状态码“ 100000002”的键表示它是您添加的自定义状态码。确保您已经发布了自定义项。

关于c# - 插入自定义实体状态码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37865957/

10-10 23:33
查看更多