As a developer perspective CRUD is the fundamental. Dynamics 365 9.x gives the full support by using Xrm.webApi makes developer life easy.It can be used in both Online & offline version of D-365.
Bellow is the list of method most commonly used for CRUD operation.
Method | Description | ||
createRecord | Creates an entity record. | ||
deleteRecord | Deletes an entity record. | ||
retrieveRecord | Retrieves an entity record. | ||
retrieveMultipleRecords | Retrieves a collection of entity records. | ||
updateRecord | Updates an entity record. | ||
isAvailableOffline | Returns a boolean value indicating whether an entity is present in user’s profile and is currently available for use in offline mode. | ||
execute | Execute a single action, function, or CRUD operation. | ||
executeMultiple | Execute a collection of action, function, or CRUD operations. |
CRUD Examples on Dynamics 365 Opportunity Entity
createRecord : Creates an entity record.
Syntax : Xrm.WebApi.createRecord(entityLogicalName, data).then(successCallback, errorCallback);
Example : Create Record
1: //Note :- Initialized the XRM boject first
2: var Xrm = parent.Xrm;
3:
4: //Step 1- Create a Javascript function
5: function createContact() {
6: var contactObj = null;
7: try {
8:
9: //Step 2 - Create the Opportunity object
10: objOppty = new Object();
11: //Step 3- field mapping
12: objOppty.name = "Mike";
13: objOppty.Isdelete = false;
14: //set optionsetvalue
15: objOppty.opportunitystatus = 2;
16: //set the lookup value & Pass the guid of the lookup
17: objOppty["parentcustomerid_account@odata.bind"] = "/accounts(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)"
18:
19: //Step 4- Call funtion
20: Xrm.WebApi.createRecord("opportunity", objOppty).then(function (result) {
21: //guid of created record is returned
22: var recordId = result.id;
23: if (recordId != null)
24: {
25: xrm.Utility.openDialog("Record is saved.");
26: }
27: })
28: .fail(function (error) {
29: Xrm.Utility.alertDialog(error.message);
30: });
31:
32: } catch (e) {
33: Xrm.Utility.alertDialog(e.message);
34: }
35: }
On my next blogg I Will cover the "Read,Update, Delete". See you soon.
Comments
Post a Comment