function CreateAccount() { var serverURL = Xrm.Page.context.getClientUrl(); var account = {}; account["name"] = "Create record Web API Example"; //set single line of text field account["address1_city"] = "Islamabad";//set single line of text field //Lookup account["primarycontactid@odata.bind"] = "/contacts(0D7AFC02-891C-E611-80E1-5065F38B0371)"; //setting existing lookup //Below code will create contact on fly and set in primarycontact //account["primarycontactid"] = { // "firstname": "Mahender", // "lastname": "Pal" //}; //optionset account["industrycode"] = 1; // set optionSet field //two options account["donotphone"] = true; //set boolean field //number account["numberofemployees"] = 20;//set whole no field //date time //account["him_approvaldate"] = new Date(); var req = new XMLHttpRequest(); req.open("POST", serverURL + "/api/data/v8.0/accounts", false); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.send(JSON.stringify(account)); if (req.readyState == 4 /* complete */) { if (req.status == 204) { var accountUri = this.getResponseHeader("OData-EntityId"); var ID = accountUri.substr(accountUri.length - 38).substring(1, 37); //get only GUID // Xrm.Utility.openEntityForm("account", ID); //Open newly created account record } else { var error = JSON.parse(req.response).error; alert(error.message); } } }
Friday, 20 May 2016
Create Record in Microsoft Dynamics CRM 2016 using Web API
Subscribe to:
Post Comments (Atom)
Read only field , get latest value from read only field in in power app portal
Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...
-
To Query MS CRM DB there are the two distinct ways. Using QueryExpression Using FetchXML Limitation of the QueryExpression is , If yo...
-
In the following code actionName is the name of action. primarycontact and parentaccount is the entityreference attribute in action. nam...
-
To retrieve meta data of global optionSet in Web API, first you will need to retrieve meta data id of option Set. So i create two functi...
No comments:
Post a Comment