Create something great

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 


        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) {


            var NewCRMRecordCreated = data["d"];

            accountId = NewCRMRecordCreated.AccountId;

            UpdateContact(accountId, accountName);


        error: function (XMLHttpRequest, textStatus, errorThrown) {





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


Join the conversation! 2 Comments

  1. […] 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 […]


  2. […] 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 […]



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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.


nice to know


, , , , , , , ,