REST CRUD (Create, Read, Update and Delete) Operations:
Initial Setup:
Download the Latest SDK.
For CRUD Operations, get the following Script files from the path
SDK\SampleCode\JS\RESTEndpoint\JavaScriptRESTDataOperations\JavaScriptRESTDataOperations\Scripts

Create two JScript Web Resources

Create a JScript Web Resource for CRUD Operations,

Retrieve Example:
Syntax: SDK.REST.retrieveRecord(id, type, select, expand, successCallback, errorCallback)
Name |
Type |
Description |
id |
String |
A String representing the GUID value for the record to retrieve. |
type |
String |
The Schema Name of the Entity type record to retrieve. |
select |
String |
A String representing the $select OData System Query Option to control which attributes will be returned. This is a comma separated list of Attribute names that are valid for retrieve.
If null all properties for the record will be returned |
expand |
String |
A String representing the $expand OData System Query Option value to control which related records are also returned. This is a comma separated list of up to 6 entity relationship names
If null no expanded related records will be returned. |
successCallback |
Function |
The function that will be passed through and be called by a successful response.
This function must accept the returned record as a parameter. |
errorCallback |
Function |
The function that will be passed through and be called by a failed response.
This function must accept an Error object as a parameter. |
Task:Get the Contact details based on Contact Guid using Retrieve Method
Solution: Add the below Script in “new_sdkOperations” Webresource for Retrieving Contact details based on “ContactId”,
function retrieveContact(ContactId) {
SDK.REST.retrieveRecord(ContactId, "Contact", null, null, getDetails, errorHandler);
}
function getDetails(contact) {
alert("Full Name : "+ contact.FullName + "\n" +
"Company Name : " + contact.ParentCustomerId.Name + "\n" +
"Guid : " + contact.ContactId +"\n" +
"Preferred Method of Contact : " + contact.PreferredContactMethodCode.Value +"\n" +
"Bulk Email : " + contact.DoNotBulkEMail +"\n"+
"Birthday : " + contact.BirthDate
);
}
function errorHandler(error) {
alert(error.message);
}
Save and Publish the Web Resource “new_sdkOperations”.
Add the 3 Web Resources in Contact Entity as follows,

Add OnLoad event, Library: new_sdkOperations &function retrieveContact

Pass the Existing Contact Guid as a Parameter to test the function,

Save and Publish the entity. Open any record to get the below alert.

Please provide your valuable comments on this article.
Like this:
Like Loading...