Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How can I save a entity with javascript?

Posted on by 225

Within a form, I have a IFrame. This IFrame list all associated entities with a button to "Enable" the entity. OnClick for the entity it uses the API to send a PATCH on the value of the entity. So far so good.

Back to the form, I have a counter that counts % of enabled entities associated with the (parent) entity in the form. But upon clicking "Enable" that entity gets a updated value, but it is not saved? In Dynamics, if I open up the child entity the value is changed but the notification down in the right side states that there are unsaved changes.

How can I fetch, update and save a underlying entity of while in another form?

*This post is locked for comments

  • Verified answer
    _Lars_ Profile Picture
    _Lars_ 225 on at
    RE: How can I save a entity with javascript?

    I resolved the problem. I was doing it right, the RESTful API saves the entity. The problem was that we had business rule in the entity where another parameters value was decided by the value I changed. I did not to this, so when I entered the entity the business logic ran and changed the second parameter and that is why I got the notification that there were unsaved changes. Setting the value and setting the second value so it matches the result of the business rule solves the problem :-)

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How can I save a entity with javascript?

    Hi,

    Try using XrmServiceToolkit.Soap for this. Use the code below.

        //Update Entity
        var updateEntity = new XrmServiceToolkit.Soap.BusinessEntity("EntityName", entityGuid);
        //Lookup to update
        updateEntity.attributes["fieldName"] = { id: entityGuid, logicalName: 'entityName', type: 'EntityReference' };
        //OptionSet
        updateEntity.attributes["fieldName"] = { value: Value, type: 'OptionSetValue' };
        //Currency
        updateEntity.attributes["fieldName"] = { value: Value, type: 'Money' };
        //Boolean
        updateEntity.attributes["fieldName"] = { value: true/false, type: 'boolean' };
        //String
        updateEntity.attributes["fieldName"] = "Value";
    
        updateEntity.attributes["fieldName"] = { Value: 2, type: "int" };
    
        updateEntity.attributes["fieldName"] = { Value: 1.5617, type: "double" };
    
        var updateResponse = XrmServiceToolkit.Soap.Update(updateEntity);

    You should also register XrmServiceToolkit.js library in the Form Properties.

    See: https://xrmservicetoolkit.codeplex.com/

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans