Monday, October 26, 2015

Update record using XrmSvcToolkit

Code Snippet:

var entity = new Object();
    entity.Name = "updated name";
    entity.NumberOfEmployees = 234;
    entity.CreditLimit = { Value: "2323" };
    entity.new_idnumber = 23.876;
    entity.new_doj = new Date();

XrmSvcToolkit.updateRecord({
                    entityName: "new_employee",
                    id: taskRecord.id,
                    entity: entity,
                    async: true,
                    successCallback: function (result) {
                        alert("Record Updated Successfully");
                    },
                    errorCallback: function (error) {
                        alert('Failed to update record');
                    }
                });

Description:

  • Firstly i have created an entity object with name entity and passed few fields(Name ,Number of employess, CreditLimit, IdNumber, Doj)to update in "new_employee" entity.
  • Must use Schema names for fields
  • You need to add XrmSvcToolkit.js file as reference in order to work with update record.
  • Pass entityName , Record Id and entity Object in UpdateRecord function
  • async:(Asynchronous) true..This record will update using Asynchronous operation ,if you need Synchronous just change as "async: false,"
  • If there are any errors in code..Then errorCallback function will be executed(This could happen if you were giving wrong filed names or using logical names or passing wrong content)
  • If it success , successCallback function will be executed and the lines inside that function will be executed...


Thank you 

No comments:

Post a Comment