简体   繁体   中英

CRM 2011: Entity form halt when plugin executed

In CRM 2011, I want to export description of email activity as doc file using plugin. I've following problem with after the execution of plugin:

Problem: It disable the email activity form.

Following is my so far code for the plugin.

IPluginExecutionContext context = (IPluginExecutionContext)isp.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)isp.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(context.UserId);
            ITracingService t_service = (ITracingService)isp.GetService(typeof(ITracingService));

            service.Update(entity);
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {

                    Entity entity = (Entity)context.InputParameters["Target"];
     string strFileName = subject + ".doc";
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Charset = "";
                    HttpContext.Current.Response.ContentType = "application/msword";
                    StringBuilder strHTMLContent = new StringBuilder();
                    strHTMLContent.Append(html);
                    HttpContext.Current.Response.Write(strHTMLContent);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    HttpContext.Current.Response.Flush();

I want to seek your kind help in this regard so that it could not disable the email activity form.

You're creating an infinite loop. You don't need to call Update when updating the target. Just make the changes you desire, and as a part of the plugin context, the changes will be made when it actually saves the entity to SQL. (This is assuming you're registered as a Pre-Update) If it needs to be registered on a Pre-Validation or a post update, use shared-variables to keep from creating an infinite loop .

The problem here is you are trying to tweak the response stream in a plugin. Plugins are not meant to do this. Plugins run serverside and are not only triggered by actions performed through the web browser interface. Eg, a console program of some middleware could also invoke the CRM API's methods.

In your case the web client sends a SOAP post message to the server, telling it to create or update an e-mail record. The client expects to receive a SOAP response message from the server. Instead it is receiving a binary stream, which it can not handle.

When the user needs to automatically download a Word document, you would need to develop a custom web service or look for a different solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM