spl*_*tto 4 .net c# dynamics-crm workflow-foundation dynamics-crm-4
我需要为Dynamics CRM 4.0编写一个插件,该插件在重新打开关闭的机会时执行,以便更改salesstagecode.我的问题是:
我通常编写异步工作流程,我编写插件的经验仍在开发中,所以我很感激可以提供任何帮助和澄清.
请参阅下面我编写的插件框架
public void Execute(IPluginExecutionContext context)
{
if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)
{
ICrmService service = context.CreateCrmService(false);
DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"];
if (entity.Name == EntityName.opportunity.ToString())
{
if (entity.Properties.Contains(/*What Property Should I Check Here?*/))
{
//And what value should I be looking for in that property?
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想你实际上想要在SetStateDynamicEntity消息上为post阶段注册一个插件.您不希望此消息有任何过滤属性.
您的代码看起来像这样:
public void Execute(IPluginExecutionContext context)
{
string state = (string)context.InputParameters["State"];
if (state == "Open")
{
Moniker entityMoniker = (Moniker)context.InputParameters["EntityMoniker"];
DynamicEntity opp = new DynamicEntity("opportunity");
opp["opportunityid"] = new Key(entityMoniker.Id);
opp["salesstagecode"] = new Picklist(/*your value*/);
context.CreateCrmService(true).Update(opp);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我最终得出的结论。我会将其标记为正确答案,但当我能够再次投票时,我会给你们俩(焦点和科里)投票,因为我采纳了你们俩的建议来达成这个解决方案。
public void Execute(IPluginExecutionContext context)
{
if (context.InputParameters.Properties.Contains("Target") &&
context.InputParameters.Properties["Target"] is DynamicEntity)
{
DynamicEntity opp = (DynamicEntity)context.InputParameters["Target"];
Picklist StageCodePicklist = new Picklist(); (Picklist);opp.Properties["salesstagecode"];
StageCodePicklist.name = "Advocating - Advanced (90%)";
StageCodePicklist.Value = 200004;
opp.Properties["salesstagecode"] = StageCodePicklist;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5763 次 |
| 最近记录: |