
Microsoft Dynamics CRM: How to create company via button click (Ribbon Workbench) – Possibility No 1
Step 0: What we want to do
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’.
Step 1: Create button in Ribbon Workbench
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.
Step 2: Command
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.
Step 3: Javascript
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"); } }); }
Step 4: Company Obsolet Created
You can now go to your firms and search for Company Obsolet.
Step 5: Input values by User
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
Share it:
- Click to share on WhatsApp (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Twitter (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to email a link to a friend (Opens in new window)
- More
- Click to share on LinkedIn (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Click to print (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to share on Telegram (Opens in new window)
- Click to share on Skype (Opens in new window)
- Click to share on Pocket (Opens in new window)
Related
Join the conversation! 2 Comments
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
About Miss Ob·so·let
Imperfection is beauty, madness is genious. it is better to be absolutely ridiculous than absolutely boring.Latest Posts By Miss Ob·so·let
- 06.08.22I asked her if she believed in love, and she smiled and said it was her most elaborate method of self-harm.
- 04.02.22Technology
- 02.24.22The best kiss is the one that has been exchanged a thousand times between the eyes before it reaches the lips.
- 02.10.22Relationships are like glass. Sometimes it's better to leave them broken than to hurt yourself putting it back together.
- 02.09.22If they make you question your worth, they’re not worth it.
[…] 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