To create a record using Xrm.WebApi, use the following syntax. We will use the example where we are creating an account record with 3 fields:
var entity = {}; entity.name = "Test Account"; var parentAccountId = "e46bf6d0-86b6-ea11-a812-000d3a300fca"; entity["parentaccountid@odata.bind"] = "/accounts(" + parentAccountId + ")"; entity.industrycode = 4; entity.websiteurl = "carldesouza.com"; Xrm.WebApi.online.createRecord("account", entity).then( function success(result) { var recordId = result.id; }, function(error) { Xrm.Utility.alertDialog(error.message); } );
The record is then created:
THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL