web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Ben Thompson Profile Picture
    6,350 on at

    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?

  • Verified answer
    Community Member Profile Picture
    on at

    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/

  • Suggested answer
    sandeepstw Profile Picture
    4,601 on at

    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

       );

    }

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

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

    github.com/.../CRMRESTBuilder

    Hope this helps.

  • Community Member Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

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

    How to debug it?

    Matt

  • Community Member Profile Picture
    on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans