On this Section we will see the How to Retrieve the records on Dynamics 365 instance.
1. To retrieve records Xrm.WebApi.retrieveRecord the required parameter is given below: - Entity Logical Name - Entity Guid - Query Capability (ex. Select cause, Filter cause)
Syntax : Xrm.WebApi.retrieveRecord("Entiy", "Guid", "$select=")
Example : Retrive Record
//Note :- Initialized the XRM boject first
var Xrm = parent.Xrm;
//Step 1- Create a Javascript fumction
/// This function is used to retrieve the contact record
function retrieveContact() {
try {
Xrm.WebApi.retrieveRecord("contact","465B158C-541C-E511-80D3-3863BB347BA8","$select=fullname,telephone1,preferredcontactmethodcode,createdon,_parentcustomerid_value,creditlimit")
.then(function (data) {
retrieveContactSuccess(data);
})
.fail(function (error) {
Xrm.Utility.alertDialog(error.message);
});
} catch (e) {
Xrm.Utility.alertDialog (e.message);
}
}
function retrieveContactSuccess(data) {
try {
//get the values
//string
var fullname=data["fullname"];
//optionset
var typeCode=data["customertypecode"];
//lookup
var customerGuid = data["_parentcustomerid_value"];
var customerName=data["_parentcustomerid_value@OData.Community.Display.V1.FormattedValue"];
var customerEntityLogicalName=data["_parentcustomerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
//money
var creditLimit=data["creditlimit@OData.Community.Display.V1.FormattedValue"];
//date
// gives date in following format 2017-09-30T21:10:19Z
var createdonFormattedValue=data["createdon@OData.Community.Display.V1.FormattedValue"];
// gives date in following format 10/1/2017 2:40 AM
var createdon=data["createdon"];
//optionset
var preferredConMethod=data["preferredcontactmethodcode@OData.Community.Display.V1.FormattedValue"];
} catch (e) {
Xrm.Utility.alertDialog(e.message);
}
}
Comments
Post a Comment