Create
Syntax: SDK.REST.createRecord(object, type, successCallback, errorCallback)
| Name | Type | Description |
| object | Object | A JavaScript object with properties corresponding to the Schema name of entity attributes that are valid for create operations. |
| type | String | The Schema Name of the Entity type record to create. |
| successCallback | Function | The function that will be passed through and be called by a successful response. This function can 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:Create a Contact Record
Solution: Add the below Script in โnew_sdkOperationsโ Webresource and click Ok.
Please do check REST – Retrieve Example for Initial Setup
function createAccount() {
var account = {};
account.Name = "Arun Potti";
account.Description = "Account was created using SDK.REST.createRecord Method";
//Set a lookup value
account.PrimaryContactId = {
Id: "FB4F88B0-49B3-E311-9C70-D89D676E8210", //Provide Existing Contact Guid
LogicalName: "contact",
Name: "Maria Campbell (sample)" ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย //Provide Existing Contact Name
};
//Set a picklist value
account.PreferredContactMethodCode = {ย ย Value: 2ย ย };
ย ย //Set a money value
account.Revenue = { Value: "2000000.00"ย ย };
ย ย //Set a Boolean value
account.DoNotPhone = true;
ย //Add Two Tasks
var today = new Date();
var startDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 3);ย ย //Set a date three days in the future.
ย //Low Priority Task
var LowPriTask = { Subject: "Low Priority Task", ScheduledStart: startDate, PriorityCode: { Value: 0 } };
//High Priority Task
var HighPriTask = { Subject: "High Priority Task", ScheduledStart: startDate, PriorityCode: { Value: 2 } };ย ย ย ย ย account.Account_Tasks = [LowPriTask, HighPriTask];
//Create the Account
SDK.REST.createRecord(account, "Account", getAccountDetails, errorHandler);
}
function getAccountDetails(account) {
alert("Account Name : " + account.Name + "\nAccount GUId : " + account.AccountId);
}
function errorHandler(error) { alert(error.message); }
Add OnLoad event in Account Form, Library: new_sdkOperations &function createAccount. Save and Publish
Output:
Please provide your valuable comments on this article.
Discover more from Arun Potti's Power Platform blog
Subscribe to get the latest posts sent to your email.


