web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

using javascript to upload files to notes

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    Anh Luu Profile Picture
    215 on at

    Maybe this post can help you:

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

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    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.

        

        

  • Suggested answer
    Soma Shekar Profile Picture
    461 on at

    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

  • Ahmad Saud Profile Picture
    790 on at

    thanks a lot Nithya Gopinath 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans