Asked by:
crm download pdf from attachment

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
-
Hi Christo,
This could be archived using multiple ways..
1. Have web page or silver light web page doing this and with web page you can query relevant attachment record and display save dialog to user
2. using java script, with this create one ribbon button which allow user to click and download attachment. internally run relevant workflow and then wait till it is finished and once it is finished open relevant attachment (note) record and with this user can download attachment from standard CRM note record
3. using dialog, well not fully sure on this but with dialog you can do wizard like process and run step which create attachment record and then display relevant note record..
MayankP
My Blog
Follow Me on TwitterMonday, May 5, 2014 1:47 PMAnswerer -
I am currently working towards option 2. I already have the button with the workflow calling in place. How can I open the new relevant attachment (note) record?
Please vote if you find my post useful. Add me on Skype @ christo.skype1
Monday, May 5, 2014 1:54 PM -
Hi Christo,
Refer following link which provide pseudo code to retrieve note
once you have note id you can use native window.open method passing url as mentioned in blog post below...
http://msdn.microsoft.com/en-us/library/gg328483.aspxMayankP
My Blog
Follow Me on TwitterMonday, May 5, 2014 2:30 PMAnswerer