Skip to main content

Notifications

Dynamics 365 Community / Forums / Sales forum / create notes with atta...
Sales forum
Suggested answer

create notes with attachments.

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:
  • p_doc Profile Picture
    p_doc on at
    create notes with attachments.
    Hi Hao,
    Thank you for the reply.
    is this a plugin code or javascipt?
     
  • 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,877 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,425 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans