Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

create notes with attachments.

(1) ShareShare
ReportReport
Posted on by
Hi community,

Is there a way to add notes with attachments to an custom entity?

I am using the below code from (Create Notes with Attachment using Web API in Dynamics 365 - Nebulaa IT Solutions | Nebulaa IT Solutions)
var note = {};

note.subject = "Notes Subject";

note.notetext = "Notes Text";

note.filename = "FileName.txt";

note.documentbody = "Base64String";

note["objectid_contact@odata.bind"] = "/contacts(00000000-0000-0000-000000000000)";

Xrm.WebApi.createRecord("annotation", note).then(

function success(result) {

alert("Success");

},

function(error) {

alert(error.message);

});

But i get error Xrm error.
I know it is depricated,
But Xrm.WebApi.offline shoudl work, but i does not 
Xrm.WebApi.offline (Client API reference) in model-driven apps - Power Apps | Microsoft Learn

I am lost, any help is apperciated.
  • Suggested answer
    Cui Hao Profile Picture
    on at
    create notes with attachments.
    Hi,
     
    This is the JavaScript code registered in the Onload event.
     
     
    Best regards,
    Cui Hao
  • Paul_M Profile Picture
    on at
    create notes with attachments.
    Hi Hao,
    Thank you for the reply.
    is this a plugin code or javascipt?
     
  • Cui Hao Profile Picture
    on at
    create notes with attachments.
    Hi,
     
    Do you have any other questions? If you have any other questions feel free to ask me.
    If it solved your problem, please mark it as verified to help other community members find more. 
     
     
     
    Best regards,
    Cui Hao
  • Suggested answer
    Cui Hao Profile Picture
    on at
    create notes with attachments.
    Hi,

    After testing, I think you are getting an error in getting the contactId.

    I have changed your code and you can add it to the onload event.
    This code now dynamically gets the guid for the current contact and then creates a note with an attachment. I have successfully run this code.



    The code is as follows:
    function createNoteWithCurrentEntity(executionContext) {
        var formContext = executionContext.getFormContext();
        var note = {};
        note.subject = "Notes Subject";
        note.notetext = "Notes Text";
        note.filename = "FileName.txt";
        note.documentbody = "Base64String";
        var entityId = formContext.data.entity.getId().replace(/[{}]/g, "");
        note["objectid_contact@odata.bind"] = "/contacts(" + entityId + ")";
        Xrm.WebApi.createRecord("annotation", note).then(
        function success(result) {
        alert("Success");
        },
        function(error) {
        alert(error.message);
        });
    }


    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.


    Best regards,
    Cui Hao

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 671 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 167 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 138 Most Valuable Professional

Product updates

Dynamics 365 release plans