Showing posts with label Getting Existing records and updating Existing records using REST service in MS Dynamics CRM. Show all posts
Showing posts with label Getting Existing records and updating Existing records using REST service in MS Dynamics CRM. Show all posts

Wednesday, 27 January 2016

Retrieve and Update Existing record

Retrieve and Update Existing record data in an entity


Here I mention using REST service Method

For that we need to add SDK.REST Javascript in your form (For getting this we need to go SampleCode-->JS-->RESTEndpoint-->JavaScriptRESTAssociateDisassociate-->JavaScriptRESTAssociateDisassociate-->Scripts)

Then create your own Javascript with following code

function RetrieveAllRecords(context) {
    var Account= "Your Custom Logic"; //Mention Which fields you want to get. For Example  "$select=new_Name"

///Parameters
//Param Name="Entity Name"-- Give your Entity Schema name based on Odata Query Designer
//For an Account record, use "Account"
///Param Name="Options"
//A String representing the OData System Query Options to control the data returned
//Param Name="SuccessCall Back" Type="function"
//Param Name="Error Call Back" Type="function"
//Param Name="OnComplete" Type="function"


       SDK.REST.retrieveMultipleRecords("Your Entity Name", searchRecords, retrieveAccountsCallBack, errorCallBack, ActiveRetrieveComplete);
}
function retrieveAccountsCallBack(retrievedAccounts, context) {
          for (var i = 0; i < retrievedAccounts.length; i++) {
               var name=retrievedAccounts[i].new_Name;
//Write your own logic here
        }
}
function errorCallBack() {
    alert(error.message);
}
function ProceedingsRetrieveComplete() { }


For updating Existing Record


First get the ID for which record you want to update.

Then again we have a method that  "updateRecord"

function updateRecord() {
var account={}
account.mobilenumber="9876543210";

//Parameters
//Param Name="GUID"
//use the GUID which record you want to update
//Param Name="object"
//based on your condiotion what you want to update
//Param Name="Type"
//The Schema Name of the Entity type record to retrieve.
//Param Name="updateSuccessCallback" , Type="function"
//Param Name="errorHandler" , Type="function"


       SDK.REST.updateRecord("GUID", account, Type, updateSuccessCallback, errorHandler); //Provide Existing Account record GUID
}

function updateSuccessCallback() {
    alert("The account record changes were saved");
}

function errorHandler(error) {
    alert(error.message);
}