locked
crm download pdf from attachment RRS feed

  • Question

  • Up to now I have done the following and got it to work:

    1. Create custom c# workflow that accept a quote.

    2. Create a workflow that calls my custom workflow from a quote.

    3. Run a quote report and add it as an attachment to the quote (in the notes section).

    All of this is working fine.  I can get my report attached to the entity in pdf format.  The problem is though, I want to reduce the number of clicks to get the actual pdf downloaded.  The ideal will be to run the workflow and after the pdf is build a save dialog box should appear on the user's screen.  

    The piece of code to render the pdf is as follow:

    try
                {
                    reportresult = rg.Render("/ProkonCRM_MSCRM/Quote", FormatType.PDF, parameters);
                }
                catch (Exception ex)
                {
                    throw new Exception("ReportResult error: " + ex.Message);
                }
    
                QueryExpression RelatedQuotesQuery = new QueryExpression
                {
                    EntityName = "quote",
                    ColumnSet = new ColumnSet("quoteid","name", "quotenumber"),
                    Criteria = new FilterExpression
                    {
                        Conditions = 
                                    {
                                        new ConditionExpression 
                                        {
                                            AttributeName = "quoteid",
                                            Operator = ConditionOperator.Equal,
                                            Values = { 
                                                        context.PrimaryEntityId.ToString() }
                                        }
                                    }
    
                    }
                };
                DataCollection<Entity> Quotes = service.RetrieveMultiple(RelatedQuotesQuery).Entities;
                Entity Quote = Quotes[0];
    
                Entity attachment = new Entity("annotation");
                attachment["objectid"] = quote.Get<EntityReference>(executionContext);
                attachment["filename"] = Quote["name"].ToString() + "-" + Quote["quotenumber"].ToString() + ".pdf"; 
                attachment["subject"] = Quote["name"].ToString() + "-" + Quote["quotenumber"].ToString();
                attachment["documentbody"] = System.Convert.ToBase64String(reportresult);
                attachment["mimetype"] = "application/pdf";

     


    Please vote if you find my post useful. Add me on Skype @ christo.skype1

    Monday, May 5, 2014 1:26 PM

All replies