Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

using javascript to upload files to notes

Posted on by Microsoft Employee

Hello

I would like to use javascript to make a custom attach button. When the user presses on attach button it brings file chose dialog and then when you select the file it attaches the file to the record and stores it in the notes (annotation entity). Can somone point me in the right direction to resources that can help me do this?

*This post is locked for comments

  • Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: using javascript to upload files to notes

    thanks a lot Nithya Gopinath 

  • Suggested answer
    Soma Shekar Profile Picture
    Soma Shekar 461 on at
    RE: using javascript to upload files to notes

    HI, Please look into the  below link,

    This will be helpful to you exactly, what you are looking for. 

    http://dynamicsobjects.com/Products/Dynamics-Attachments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: using javascript to upload files to notes

    Hi,

    Follow the steps below to achieve this functionality.

    1. Create a Global Action which accepts the input parameter as the RecordId.

    88822.2.PNG

    88822.2.PNG

        See: http://www.powerobjects.com/2013/11/22/actions-in-dynamics-crm-2013/

    2. Create a Javascript Web Resource with the code below.

    function ExecuteGlobalAction(recordId, entityName) {
        //Execute the created global action using Web API.
        //get the current organization name
        var serverURL = Xrm.Page.context.getClientUrl();
        //query to send the request to the global Action 
        var query = "new_AttachFile";
        //Pass the input parameters of action
        var data = {
            "RecordId": recordId,
    "EntityName": entityName }; //Create the HttpRequestObject to send WEB API Request var req = new XMLHttpRequest(); //Post the WEB API Request req.open("POST", serverURL + "/api/data/v8.2/" + query, true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { result = JSON.parse(this.response); } else { var error = JSON.parse(this.response).error; alert(error.message); } } }; //Execute request passing the input parameter of the action req.send(window.JSON.stringify(data)); }

        See: https://www.inogic.com/blog/2016/10/execute-the-global-action-using-web-api-in-dynamics-crm/

    3. Open the Ribbon Workbench and create a new button and a new command.

        See: https://ribbonworkbench.uservoice.com/knowledgebase/articles/71374-1-getting-started-with-the-ribbon-workbench

    • If the button is created in Subgrid level, then in the command, Add Action as Javascript Action with Function Name as ExecuteGlobalAction and in the Parameters, add CRM Parameters as FirstSelectedItemId and SelectedEntityTypeName.
    • If the button is created in Form level, then in the command, Add Action as Javascript Action with Function Name as ExecuteGlobalAction and in the Parameters, add CRM Parameter as FirstPrimaryItemId and PrimaryEntityTypeName.

    4. Create a Plugin to choose a file using dialog, read the file and convert it to the base64 string. Create an annotation record with the base64string as documentbody field, filename field as the name of the file read, isdocument field as true, objectid field as the RecordId (passed from Javascript as input parameter of action), objecttypecode field as the entityName (passed from Javascript as input parameter of action).

        See: https://stackoverflow.com/questions/25919387/c-sharp-converting-file-into-base64string-and-back-again

    5. Register the Plugin Assembly using Plugin Registration Tool and register a new step as shown below.

    80771.3.PNG

       See: https://www.greenbeacon.com/insights/trigger-plugin-from-ribbon-button-using-custom-actions-in-dynamics-crm-2013/

    Hope this helps.

        

        

  • Verified answer
    Anh Luu Profile Picture
    Anh Luu 215 on at
    RE: using javascript to upload files to notes

    Maybe this post can help you:

    scaleablesolutions.com/upload-notes-attachments-using-javascript-and-rest

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans