Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieving and updating an entities data javascript

(0) ShareShare
ReportReport
Posted on by

Am wading through converting  CRM 4 to 2011 and have gone blank on how to update a record:

       var serverUrl = document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
        var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
        oDataEndpointUrl += "A_counterSet?$select=A_counterId, A_Count&$filter=A_name eq 'A_Ref'";

        var service = GetRequestObject();
        if (service != null)
        {
            service.open("GET", oDataEndpointUrl, false);
            service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
            service.setRequestHeader("Accept", "application/json, text/javascript, */*");
            service.send(null);
            var requestResults = eval('(' + service.responseText + ')').d;

            if (requestResults != null && requestResults.results.length > 0)
            {
                var value = requestResults.results[0].A_Count;
                var CCount = parseFloat(value) +1;

                var res = getNo(Xrm.Page.getAttribute("A_pcode").getValue()) + CCount;
                Xrm.Page.getAttribute("A_projectreference").setSubmitMode("always"); 
                Xrm.Page.getAttribute("A_projectreference").setValue(res);

                var CCountID = requestResults.results[0].A_counterId;


            }
        }


I am retrieving a counter and then want to add 1 to it and then write this back to the system, just struggling to understand how.

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Retrieving and updating an entities data javascript

    I couldn't get this to work with an existing custom entity (entity carried forward from crm4 to 2011) so recreated entity as my own and the code works perfectly - just can't see why it didn't work with original entity?

    Matt

  • Community Member Profile Picture
    on at
    RE: Retrieving and updating an entities data javascript

    Tried this but just receive an error "error, Error Thrown: undefined"

    How to debug it?

    Matt

  • Community Member Profile Picture
    on at
    RE: Retrieving and updating an entities data javascript

    Currently just looking to migrate this CRM 4 system to 2011 and then bounce to 2013 - Most probably the system will sit there while we look to do a complete new CRM system for the company - Viewpoint is that this could be a quick and dirty upgrade buying us a little time to look at the new system.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    RE: Retrieving and updating an entities data javascript

    Try download CRM Rest Builder. This will help you with coding your REST API calls.

    github.com/.../CRMRESTBuilder

    Hope this helps.

  • Suggested answer
    sandeepstw Profile Picture
    4,601 on at
    RE: Retrieving and updating an entities data javascript

    Hi,

    Download XRM toolkit fom here archive.codeplex.com and

    Add in form js lib using form property as per image:

    fetchxml_2D00_pic_2D00_2.png

    function GetAttributeValueFromID(sEntityName, sGUID)

    {

    var items;

    XrmServiceToolkit.Rest.Retrieve(

                   sGUID,

                   sEntityName,

                   null, null,

                   function (result) {  

    items = result;

    return result;

                   },

                   function (error) {

                       equal(true, false, error.message);

                   },

                   false

               );

    return items;

    }

    // create object in js

    var eEntityObject= {};               
      entityObject.Address1_Name = Xrm.Page.getAttribute("new_address1name").getValue();           
      entityObject.Address1_Line1 = Xrm.Page.getAttribute("new_address1street1").getValue();
      entityObject.Address1_Line2 = Xrm.Page.getAttribute("new_address1street2").getValue();
      entityObject.Address1_City = Xrm.Page.getAttribute("new_address1city").getValue();
      entityObject.Address1_PostalCode = Xrm.Page.getAttribute("new_address1zippostalcode").getValue();
      entityObject.Address1_StateOrProvince = Xrm.Page.getAttribute("new_address1stateprovince").getValue();
      entityObject.Address1_Country = Xrm.Page.getAttribute("new_address1countyregion").getValue();

    // update object

    function UpdateAttributeValueFromID(eEntityObject,sEntityName, sGUID)

    {

    XrmServiceToolkit.Rest.Update(

           sGUID,

           eEntityObject,

           sEntityName,

           function () {

               //alert("Address has been successfully exported to Creditor.");

           },

           function (error) {

                       equal(true, false, error.message);

           },

           false

       );

    }

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Retrieving and updating an entities data javascript

    Hi, 
    Maybe this link can help you, it uses the CRM 2011 SDK that you can download here

    https://lakshmanindian.wordpress.com/2012/10/11/update-record-using-jscript-in-microsoft-dynamics-crm-2011/

  • Ben Thompson Profile Picture
    6,350 on at
    RE: Retrieving and updating an entities data javascript

    Why are you converting any code to the CRM 2011 soap interface, its deprecated and will rapidly become end of life. Unless you are migrating to a 2011 / 13 system you really should be using the webapi in its 8.1 /8.2 or 9.0 versions?

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans