Creating Dynamics CRM Plugin to execute external task

我怕爱的太早我们不能终老 提交于 2019-12-02 08:21:11

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.

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.

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.

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.

I'll tag on to Aron's excellent answer for those that are more visual learners. Below from a high point is what happens when you execute a normal CRUD operation in CRM:

The plugin itself is executing in steps 2 or 4, depending on how you've registered it, but regardless, it is executing in an online sandbox process that is isolated from all other processes on the machine in the cloud that is processing it. The sandbox puts additional restrictions on your code, once of which is disk access. You can not access any portion of the hard drive from a plugin, so attempting to read or write a file will fail. And trying to open up an application makes no sense, because even if it were allowed, it would open on some webserver in some webfarm in Microsoft's cloud, not on your local machine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!