创建Dynamics CRM插件以执行外部任务 [英] Creating Dynamics CRM Plugin to execute external task

查看:190
本文介绍了创建Dynamics CRM插件以执行外部任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试CRM插件.我的最终目标是创建一个插件,该插件将运行另一个仅将项目凭据添加到excel文件的程序.对于我的示例项目,我基本上只是遵循

I am experimenting with CRM Plugins. My end goal is to create a plugin that will run another program that just adds project credentials to an excel file. For my sample project, I essentially just followed https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/tutorial-write-plug-in. The example provided here was excellent and taught me a lot about Plugins. The issue I am having is, whenever I try to execute code that was not involved in the tutorial, I get an error and the debug process doesn't even hit my break point. When I remove my personal code from the function, it works fine.

public class PostCreateContact : IPlugin
{

    public void Execute(IServiceProvider serviceProvider)
    {


        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        //Process firstProc = new Process();
        //firstProc.StartInfo.FileName = "notepad++.exe";
        //firstProc.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Notepad++\\notepad++.exe";
        //firstProc.EnableRaisingEvents = true;
        //firstProc.Start();
        if (context.InputParameters.Contains("Target")&& context.InputParameters["Target"] is Entity)
        {
            Entity entity = (Entity)context.InputParameters["Target"];
            try
            {
                Entity followup = new Entity("task");
                followup["subject"] = "Send e-mail to the new customer.";
                followup["description"] = "Follow up with the customer. Check if there are any new issues that need resolution.";
                followup["scheduledstart"] = DateTime.Now;
                followup["scheduledend"] = DateTime.Now.AddDays(2);
                followup["category"] = context.PrimaryEntityName;

                if (context.OutputParameters.Contains("id"))
                {
                    Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
                    string regardingobjectidType = "contact";
                    followup["regardingobjectid"] = new EntityReference(regardingobjectidType, regardingobjectid);
                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                    service.Create(followup);
                }
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
    }
}

我注释掉的5行代码是我提到的我的个人代码.如果我要取消注释这些行.该代码不会达到我的断点.我的断点设置在"public void Execute(IserviceProver servicerProvider)"行下方.有人可以向我解释为什么当我插入自己的代码来执行与CRM无关的任务时,它立即失败吗?

The 5 lines of code that I have commented out are my personal code i mentioned. If I were to un-comment out those lines. The code will not hit my break point. My break point was set below the "public void Execute(IserviceProver servicerProvider)" line. Could someone explain to me why it immediately fails whenever I insert my own code to perform a non CRM related task?

此外,除了尝试打开记事本++之外,尝试抛出消息框也将不起作用.

Also, besides attempting to open up notepad++, attempting to throw a message box will not work either.

推荐答案

插件的性质是,它们在Dynamics 365系统中的数据上运行,或者通过HTTP或HTTPS与外界通信.写入本地文件超出了插件设计的范围.

The nature of plugins is that they operate on data within the Dynamics 365 system or they communicate with the outside world via HTTP or HTTPS. Writing to a local file is outside the realm of what plugins are designed to do.

让插件与外界通信的一种方法是编写一个

One way to have a plugin communicate with the outside world is to write a an Azure-aware plugin.

如果您的系统是本地系统,请在沙盒可以提供更大的灵活性,即使写入本地文件,即使在技术上可行(我不认为这是可能的)仍然会很糟糕练习.

If you're system is on-premise, registering your plugins outside the sandbox would provide greater flexibility, though writing to a local file, even if it were technically possible (which I don't believe it is) would still be a bad practice.

要以受支持的方式向用户发送文件,您可以将该文件创建为注释附件.完成此操作后,您可以简单地通过电子邮件向用户发送指向Dynamics 365中该注释的链接.

To send the user a file in a supported way you could create the file as a note attachment. Once you've done that you could simply email the user a link to that Note in Dynamics 365.

如果您希望文件在Dynamics 365之外可用,则可以触发Azure- 知道其插件是基于Azure的侦听器的插件将检索Note附件文件,将其上传到SharePoint或OneDrive之类的云文件服务,然后通过电子邮件向用户发送该文件的链接.

If you want the file to be available outside of Dynamics 365 you could trigger an Azure- aware plugin who's Azure-based listener would retrieve the Note attachment file, upload it to a cloud file service like SharePoint or OneDrive, then email the user a link to the file.

由于即使是沙盒插件也可以使用HTTPS,因此表面上您可以让插件直接将文件上传到外部云主机,但是身份验证可能会很麻烦.而且,根据上传速度和文件的大小,您可能会遇到沙箱2分钟超时的情况.

Since even sandboxed plugins can use HTTPS, you could ostensibly have a plugin upload the file directly to an external cloud host, but authentication might get thorny. And, depending on the upload speed and the size of the file you could run up against the sandbox's 2-minute timeout.

如今,标准做法是假设任何本地系统都可能在某天联机,因此设计所有代码以在沙箱中运行.

Standard practice these days is to assume that any on-prem system might move online someday, so design all code to operate in the sandbox.

这篇关于创建Dynamics CRM插件以执行外部任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆