Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / create notes with atta...
Sales forum
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.
Categories:
  • Cui Hao Profile Picture
    Cui Hao 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
    Cui Hao 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

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284,876 Super User

#2
Ludwig Reinhard Profile Picture

Ludwig Reinhard Microsoft Employee

#3
Martin Dráb Profile Picture

Martin Dráb 225,425 Super User

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans