web
You’re offline. This is a read only version of the page.
close
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.
I have the same question (0)
  • 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
  • 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
  • Paul_M Profile Picture
    on at
    create notes with attachments.
    Hi Hao,
    Thank you for the reply.
    is this a plugin code or javascipt?
     
  • 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

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

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans