Skip to main content

Notifications

Announcements

No record found.

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 4
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
    4 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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans