none
How do I download an attachment from an annotation using client-side JScript? CRM 2011

    Question

  • I'm trying to provide a link to the attachment of a note through the client-side JScript. The standard MS-made Notes component does this through the following url:

    [serverurl]/[appname]/Activities/Attachment/download.aspx?AttachmentType=5&AttachmentId={blahblahblah}&IsNotesTabAttachment=1&CRMWRPCToken=blahblahblah&CRMWRPCTokenTimeStamp=blahblahblah

    The problem is that I don't know how to get the Token or TokenTimeStamp, so I'm receiving an Access Denied error ("form is no longer available, security precaution, etc").

    The only other way I can think of doing this is through the OData endpoint, but that would at best get me a base64 string that I still would have translate into a filestream to give to the browser (all of which seems like it would take forever to implement/figure out).

    I've found a few other posts that describe the same thing, but no one has answered them:

    http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/6eb9e0d4-0c0c-4769-ab36-345fbfc9754f/

    http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/6eb9e0d4-0c0c-4769-ab36-345fbfc9754f

    http://social.microsoft.com/Forums/is/crm/thread/45dabb6e-1c6c-4cb4-85a4-261fa58c04da

    Thursday, June 07, 2012 7:34 PM

Answers

  • One of the workaround solution to get rid of that Token thing by modifying the registry and adding IgnoreTokenCheck.

    • Open the Regedit:
    • Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM
    • Add a DWORD called IgnoreTokenCheck with a value of 1

    But I am not sure about the security issue and the complication behind turning off this security token check though.

    If you're looking for the solution about getting the data from OData endpoint and translating into a filestream to give to the browser, there is already one and you can check the sample code in the following link.

    http://blogs.msdn.com/b/crm/archive/2011/09/28/displaying-a-contact-s-facebook-picture-in-microsoft-dynamics-crm-2011.aspx

    But since DataURI schema doesn't support IE <= 7, you will need to check with the users about their IE version and if they're OK with minimum requirement of IE8.

    • Marked as answer by VVander Friday, June 08, 2012 12:46 PM
    Friday, June 08, 2012 6:47 AM

All replies

  • One of the workaround solution to get rid of that Token thing by modifying the registry and adding IgnoreTokenCheck.

    • Open the Regedit:
    • Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM
    • Add a DWORD called IgnoreTokenCheck with a value of 1

    But I am not sure about the security issue and the complication behind turning off this security token check though.

    If you're looking for the solution about getting the data from OData endpoint and translating into a filestream to give to the browser, there is already one and you can check the sample code in the following link.

    http://blogs.msdn.com/b/crm/archive/2011/09/28/displaying-a-contact-s-facebook-picture-in-microsoft-dynamics-crm-2011.aspx

    But since DataURI schema doesn't support IE <= 7, you will need to check with the users about their IE version and if they're OK with minimum requirement of IE8.

    • Marked as answer by VVander Friday, June 08, 2012 12:46 PM
    Friday, June 08, 2012 6:47 AM
  • You can get a valid URL that includes the token and timestamp with the following code that uses jQuery.  This method gets the annotation form and scrapes it for the token and timestamp needed for a valid URL.  The URL parameter here is the URL to the annotation object which is in the form of https://<yourCRMServerURL>/userdefined/edit.aspx?etc=5&id={YourNoteGUIDHere}

    $.get(URL, function (data) {
                    var WRPCTokenElement = $(data).find("[WRPCTokenUrl]");
                    if(WRPCTokenElement)
                    {
                        var WRPCTokenUrl = WRPCTokenElement.attr("WRPCTokenUrl");
                        if (WRPCTokenUrl) {
                            URL = "/Activities/Attachment/download.aspx?AttachmentType=5&AttachmentId={" + annotation.id + "}&IsNotesTabAttachment=undefined" + WRPCTokenUrl;
                            window.open(URL);
                        }
                    }
                });

    
    


    Steven Rasmussen


    Tuesday, October 09, 2012 9:20 PM