We want to create a company by only clickin’ a button. After the button is clicked, we got a new company called ‘Company Obsolet’ with the phone number ‘12345’ and the fax number ‘54321’.
You have to go to Ribbon Workbench and create a new button there. My button is called ‘VERBANLTEST’:
You can see that I already inserted a Command, that’s the Command of Step 2.
My button ‘VERBANLTEST’ does not yet know what to do. That’s why we enter a command. My command itself is written in a Javascript, the one out of Step 3. So I entered a Custom Javascript Action and inserted my function out of Step 3. In addition to that, I entered an Enable Rule. I used exactly the same Enable Rule as I used when I removed a company out of a group of companies.
You need to create a webresource and enter the following Javascript:
function CreateAccount() { var accountId, accountName; var context = Xrm.Page.context; var serverUrl = context.getServerUrl(); var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; var CRMObject = new Object(); // Specify the ODATA entity collection var ODATA_EntityCollection = "/AccountSet"; // Define attribute values for the CRM object you want created CRMObject.Name = "Company Obsolet"; accountName = "Company Obsolet"; CRMObject.Telephone1 = "12345"; CRMObject.Fax = "54321"; //Parse the entity object into JSON var jsonEntity = window.JSON.stringify(CRMObject); //Asynchronous AJAX function to Create a CRM record using OData $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", datatype: "json", url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection, data: jsonEntity, beforeSend: function (XMLHttpRequest) { //Specifying this header ensures that the results will be returned as JSON. XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { alert("success"); var NewCRMRecordCreated = data["d"]; accountId = NewCRMRecordCreated.AccountId; UpdateContact(accountId, accountName); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("failure"); } }); }
You can now go to your firms and search for Company Obsolet.
I suggest you don’t always want to create the same company. So if you want to take the input of a user to specify the values, you can use a command like this:
accountName = window.prompt(“Enter Name of your Company!”);
The input of the user will be saved into the variable accountName.
See also: Microsoft Dynamics CRM: How to create company via button click (Ribbon Workbench) – Possibility No 2
This site uses Akismet to reduce spam. Learn how your comment data is processed.
[…] Post Microsoft Dynamics CRM: How to create company via button click (Ribbon Workbench), I showed you Possibility No 1 to create a company via button click. Now, I found out another […]
LikeLike
[…] Post “Microsoft Dynamics CRM: How to create company via button click (Ribbon Workbench)“, I showed you Possibility No 1 to create a company via button click, or here for Possibility […]
LikeLike