Home

Jan 16, 2012

Convert text field to link button to open CRM record

I was working on a requirement to display a readonly field on a form and it should open a record if clicked. This can be achieved by adding a text field and then converting it to link button. It can be done by calling below function. Test Account is the link button added to account form.

google.com can be replaced by CRM record url. 

function ConvertToLink(fldName) {
var btn = "<a href='javascript: void(0);' onclick=\"window.open(\'http://www.google.com\', \'windowname1\', \'width=600, height=650\'); return false;\" style='color:blue;text-decoration:underline !important'>Test Account</a>";
var ctrl = Xrm.Page.ui.controls.get(fldName)._control;
// Add the new button
ctrl.get_element().innerHTML += btn;
// Hide the textbox
ctrl.get_element().firstChild.style.display = 'none';
}
image
image

You can refer this for more details on similar customization.


Happy JS,

6 comments:

Unknown said...

Amol you are awesome! Thanks for the information!

Unknown said...

Amol, as always, this is a an easy solution. Thank you!

jd said...

This works Perfectly in CRM 2011...however we are updating to CRM 2013 soon and I have been unable to get it to work in the free Trial version of 2013. It keeps giving a null value at the "Var ctrl" line, the field is there, and I have double-checked the field name to make sure I didn't transfer over anything incorrectly. Any ideas?

Any help would be greatly appreciated.

Thanks,
JD

Dharmraj Chudasama said...

Even I am facing issue with CRM 2013, any help would be appreciated.

suresh sorde said...

Hi All,
for mscrm 2013..

var ctrl = document.getElementById(fieldname+"_d");

// Add the new button
//ctrl.get_element().innerHTML += btn;
ctrl.innerHTML += btn;
// Hide the textbox
//ctrl.get_element().firstChild.style.display = 'none';
ctrl.firstChild.style.display = 'none';

Thanks
Suresh Sorde

suresh sorde said...

Hi all,

Little changes to make it work for crm 2013..


var ctrl = document.getElementById("new_servicerequestno_d");
// var ctrl = Xrm.Page.ui.controls.get("new_servicerequestno_i")._control;
alert("s"+ctrl);
// Add the new button
//ctrl.get_element().innerHTML += btn;
ctrl.innerHTML += btn;
// Hide the textbox
//ctrl.get_element().firstChild.style.display = 'none';
ctrl.firstChild.style.display = 'none';


Thanks
Suresh