Basics CRUDE JavaScript V9.x webapi Unified Interface

Sabjan SamaDyn365CE6 years ago10 Views

Hello,

Thanks for visiting, some goodies for you.

Recently I have met CRM MVP Guido Preite  came to know the beauty of webapi on JavaScirpt. Smart code and quick development by XRM.WebApi wrapper for server side calls on clientside. Amazing part is, response is quite fast.

 

function CreateRecord() {

var data =

{

“name”: “Sample Account”,

“primarycontactid”:

{

“firstname”: “John”,

“lastname”: “Smith”

},

“opportunity_customer_accounts”:

[

{

“name”: “Opportunity associated to Sample Account”,

“Opportunity_Tasks”:

[

{ “subject”: “Task associated to opportunity” }

]

}

]

}

 

// create account record

Xrm.WebApi.createRecord(“account”, data).then(

function success(result) {

alert(“Account created with ID: ” + result.id);

// perform operations on record creation

},

function (error) {

alert(error.message);

// handle error conditions

}

);

}

 

function deleteRecord() {

var id = “94ab9061-781d-e911-a981-00224800c940”;

Xrm.WebApi.deleteRecord(“account”, id).then(

function success(result) {

alert(“Account deleted”);

// perform operations on record deletion

},

function (error) {

alert(error.message);

// handle error conditions

}

);

}

 

function updateRecord() {

var id = “c8714c94-8a1d-e911-a983-00224800c5df”;

// define the data to update a record

var data =

{

“name”: “Updated Sample Account “,

“creditonhold”: true,

“address1_latitude”: 47.639583,

“description”: “This is the updated description of the sample account”,

“revenue”: 6000000,

“accountcategorycode”: 2

}

// update the record

Xrm.WebApi.updateRecord(“account”, id, data).then(

function success(result) {

alert(“Account updated”);

// perform operations on record update

},

function (error) {

alert(error.message);

// handle error conditions

});

}

function retrieveRecord() {

var id = “c8714c94-8a1d-e911-a983-00224800c5df”;

Xrm.WebApi.retrieveRecord(“account”, id, “?$select=name&$expand=primarycontactid($select=contactid,fullname)”).then(

function success(result) {

alert(“Retrieved values: Name: ” + result.name + “, Primary Contact ID: ” + result.primarycontactid.contactid + “, Primary Contact Name: ” + result.primarycontactid.fullname);

// perform operations on record retrieval

},

function (error) {

alert(error.message);

// handle error conditions

}

);

}

 

Further read // JavaScript source code works for v9.1 https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi

ping me if you have any queries, hope this helped you.

Thank you!

Original Post https://mscrmsama.wordpress.com/2019/02/07/basics-crude-javascript-v9-x-webapi/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...