我需要能够仅在相关商机有statecode
1
在我的代码中,我可以使用Microsoft Dynamics SDK提供的GenerateSalesOrderFromOpportunityRequest类在创建商机关闭活动时创建新的销售订单。
此方法的缺点是,当机会以赢(opportunityclose
)或丢失(1
)关闭时,系统会创建2
活动。此外,opportunityclose
活动中没有任何属性表明它是赢还是输。所以找到它的唯一方法是从相关的机会中获取该属性。
在我的代码中,我能够从相关商机中获取其他属性,例如name
,但我无法获得statecode
其他0
的任何其他值}}
这是我的代码:
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
if (postImageEntity.LogicalName == "opportunityclose" && postImageEntity.Attributes.Contains("opportunityid") && postImageEntity.Attributes["opportunityid"] != null)
{
// Create an entity reference for the related opportunity to get the id for the GenerateSalesOrderFromOpportunityRequest class
EntityReference entityRef = (EntityReference)postImageEntity.Attributes["opportunityid"];
// Retrieve the opportunity that the closed opportunity activity was created for.
Entity RelatedEntityRef = service.Retrieve("opportunity", entityRef.Id, new ColumnSet( new String[] {"statecode","statuscode", "name"}));
OptionSetValue StateCode = (OptionSetValue)RelatedEntityRef.Attributes["statecode"];
OptionSetValue StatusCode = (OptionSetValue)RelatedEntityRef.Attributes["statuscode"];
string OppName = (string)RelatedEntityRef.Attributes["name"];
if (entityRef.LogicalName == "opportunity" && StateCode.Value == 1)
{
try
{
GenerateSalesOrderFromOpportunityRequest req = new GenerateSalesOrderFromOpportunityRequest();
req.OpportunityId = entityRef.Id;
req.ColumnSet = new ColumnSet(true);
GenerateSalesOrderFromOpportunityResponse resp = (GenerateSalesOrderFromOpportunityResponse)service.Execute(req);
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
回顾:为了实现这一点,我只需要能够获得与statecode
相关的opportunity
的实际opportunityclose
值。目前,即使我知道商机的州代码为0
,我也只能获得1
。
其他信息:
答案 0 :(得分:0)
您无法查看查看状态是赢还是输的机会。我
如果需要,您可以检索OpportunityClose并更改状态 https://msdn.microsoft.com/en-us/library/gg334301.aspx
我认为它将机会关闭设置为1,因为您正在执行GenerateSalesOrderFromOpportunityRequest,只有在您赢得机会时才会这样做(例如,您不会失去机会)。