Create a button on your form

This is an example on how to create a button on the form, based on a former idea of Cornel. First of all we need to create a nvarchar attribute and put it on the form where we want our button. I assume that everybody knows how to create an attribute and put in on the form, so i won’t talk about this.
In this example my attribute’s schema name is new_button. Here is the code:

// This is how we call the button, what we see
crmForm.all.new_button.DataValue = “Ok”;
// We could align it a bit = “center”;
crmForm.all.new_button.vAlign = “middle”;
//we make the mouse look as a hand when we’re moving over = “hand”; = “#CADFFC”; = “#FF0000”; = “#330066”; = “bold”;
crmForm.all.new_button.contentEditable = false;
//we attach some events in order to make it look nice πŸ™‚
function color3() { = “#6699FF”;
function color4() { = “CADFFC”;
function color1() { = “000099”;
function color2() { = “FF0000”;
//here we attach what we want our button do
Here is how the button looks like:

I didn’t define here the “someFunction”, i leave it up to you. First time when i used such a button was to add product to a quote without click-ing on “New Quote Product”, calling a Web Service…


  1. Hi, thank you for posting on your blog. It is very helpfull for me. I have just opened my own blog and I wonder if I could post your script on it with instruction in my home language (polish). Please let me know.

  2. Nice example and nice buttons too. You should really check MarioΒ΄s blog on this topic. Thanks both of you for sharing your code.

  3. Thank you very much for writing this article…it makes my life much easier…

    I spent hours working on making toolbar buttons and configuring the isv.config file. But this is actually what I needed.

  4. I just wanted to make sure of one thing. This code to create the button, should it be placed in the OnLoad event of the crmForm?

  5. yes Lucius, on the OnLoad event u alter that textbox properties until it comes to a button πŸ˜› don’t forget to add the event handlers/functions to make it act like one too… good luck

  6. Reyly greate idea!
    Just when I trying to add the handler in this way:
    it fails “window doesn’t contains the method.”
    How we’re creating and attaching a handler?

  7. Kim, if u want to make a function be triggered on a certain event for your button, you should try like this:

    // example 1 – simple function
    function SaySomethingFunny() {
    alert(“Dear diary! Jackpot!”);

    // example 2 – function with params
    function SaySomethingFunny(message) {
    crmForm.all.your_button.attachEvent(“onclick”,function() { SaySomethingFunny(“Giggity”); });

    Hope this helps πŸ™‚

  8. great job!!
    One small issue, the text in the button can be changed. But setting the field to read-only solves this

    Marcel van den Aker

Leave a comment

Your email address will not be published. Required fields are marked *