Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

SDK.REST.updateRecord with different schema names for update

Posted on by Microsoft Employee

Hi guys

I have a problem with the SDK.REST.updateRecord function for javascript.

When you want to make an update, it's something like that:

var account = {};
account.Name = "TestAccount";
SDK.REST.updateRecord(account.Id, account, "Account", function() {}, function() {});

The red marked word is a schema name on the entity account. Is there a way that I can make it more flexible? I mean, can I set a variable where the red marked keyword is?

For example:

//attributeName is a string that can be different each time
var attributeName = GetAttributeName();

var account = {};
account.attributeName = "TestAccount";
SDK.REST.updateRecord(account.Id, account, "Account", function() {}, function() {});

I know, that the code above cannot work, but is there a way it works?

Thanks for your support.

Greets,

Dominik

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.updateRecord with different schema names for update

    Thank you guys, now it works :)

    A few rows before this function, I used the ToLowerCase function. There was caused an error.

    You all gave me the correct answers!

    Thanks.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.updateRecord with different schema names for update

    You are saying this works

    var account = {};
    account.Name = "First update";
    SDK.REST.updateRecord(account.Id, account, "Account", function() {}, function() {});


    And that not works?

    var account = {};
    account["Name"] = "Second update";
    SDK.REST.updateRecord(account.Id, account, "Account", function() {}, function() {});


    From  javascript point of view, it is the same thing so it seems strange.

    Please give a try to either procedure and tell us about the error.

    If you found the answer helpful, please mark as Verified 

    Thank you & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: SDK.REST.updateRecord with different schema names for update

    Is there an error?

    Are you sure you are passing correct account id to the updateRecord call?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.updateRecord with different schema names for update

    Unfortunately, it doesn't work in my organization. Should this work for CRM 2013?

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.updateRecord with different schema names for update

    This will work:

    var account = {};
    account["Name"] = "Some value";
    SDK.REST.updateRecord(account.Id, account, "Account", function() {}, function() {});


    If you found the answer helpful, please mark as Verified 

    Thank you & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: SDK.REST.updateRecord with different schema names for update

    I think you might try

    account["attributeName"] = Value;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.updateRecord with different schema names for update

    Thanks Alex.

    But is it possible to make something like that?

    var schemaName = "Name";

    var account = {};

    account.schemaName = "TestAccount"

    SDK.REST.updateRecord(account.Id, account, "Account", function() {}, function() {});

    "account.schemaName" should be "account.Name", because I created the variable schmeName with the Value "Name". I know that this is causing an error but is there another way?

    Thanks :)

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: SDK.REST.updateRecord with different schema names for update

    Here is a sample from the SDK - you can use any account attribute there:

    function updateAccount(AccountId) {

    var account = {};

    writeMessage("Changing the account Name to \"Updated Account Name\".");

    account.Name = "Updated Account Name";

    writeMessage("Adding Address information");

    account.Address1_AddressTypeCode = { Value: 3 }; //Address 1: Address Type = Primary

    account.Address1_City = "Sammamish";

    account.Address1_Line1 = "123 Maple St.";

    account.Address1_PostalCode = "98074";

    account.Address1_StateOrProvince = "WA";

    writeMessage("Setting E-Mail address");

    account.EMailAddress1 = "someone@microsoft.com";

    SDK.REST.updateRecord(

        AccountId,

        account,

        "Account",

        function () {

         writeMessage("The account record changes were saved");

         deleteAccount(AccountId);

        },

        errorHandler

      );

    }

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans