Archive

Posts Tagged ‘CRM form’

Set field values using query string parameters on Form load in CRM

October 11, 2011 Leave a comment

Hi,

I have got below requirement,

  •  I need to open a CRM form from my custom ‘.aspx’ page.
  • On opening of the form I should populate “name” field with value

After referring MSDN article, I came to know that we can set the field values using “extraqs” query string parameter and it must meet below requirements.

  • You must encode the parameters passed in the extraqs parameter. Use encodeURIComponent to encode the parameters.
  • The names of the query string arguments must match or include the names of attributes for the entity.
  • The value cannot be a script (To prevent script injection)

Below is the sample JScript to open a form and populate “name” field on form load

function openform() {
var encodedString = encodeURIComponent(“new_name=rajeev pentyala”);
window.open(“http://ServerName/OrgName/main.aspx?etc=10014&extraqs=” + encodedString + “&pagetype=entityrecord”);
}

  • Here “new_name” is the name of attribute

You get the CRM form as below, when you call the above function

extraqs query parameter

extraqs query parameter

Please refer below useful MSDN articles

Hope it helps 🙂

Advertisement

How to change CRM form field’s label text and color using Jscript

September 15, 2011 1 comment

Hi,

Below is the sample JScript to change the color and text of  CRM form field’s  label; Place the code in JScript “onload” event

// To change color

if(crmForm.all.new_fieldname != null) {

var field = crmForm.all.new_fieldname_c; //”_c” is the caption (i.e.,Label)

if (field != null)

field.style.color = ‘gray’; //Specify your desired color

}

Same script work for both CRM 4.0 & CRM 2011

// To set the label

Xrm.Page.ui.controls.get(fieldname).setLabel(‘New label’);

🙂

Disabling form in CRM 2011

Hi,

Here is the Jscript code to disable the CRM Form (i.e., Fields on the form)

function doesControlHaveAttribute(control){

var controlType = control.getControlType();

return controlType != “iframe” && controlType != “webresource” && controlType != “subgrid”;

}

function disableFormFields(truefalse){

Xrm.Page.ui.controls.forEach(function(control, index) {

if (doesControlHaveAttribute(control)){

control.setDisabled(truefalse);

}

});

}

How do I call this?

  • To disable Form  – disableFormFields(true)
  • To Enable Form  –  disableFormFields(false)

Hope it Helps 🙂

Handling Tab click event in CRM 2011

Hi,

We can fire our own Jscript function on CRM tab click. Below are the steps

 How to get ID of Crm Form Tab :-

  • Get the ID of the ‘Tab’, using IE browser Developer Tool (i.e., Click F12)  (See image above)

Code :-

  • Attach “onclick” event handler on page ‘OnLoad’ method

function Form_onload() {
//Attach ‘onclick’ event handler to “Tab”
var linkGeneral = document.getElementById(“tab0Tab”);   //’tab0Tab’ is the ID of ‘General tab’
if (linkGeneral) {
linkGeneral.attachEvent(“onclick”, tab_onclick);

}

}

Function tab_onclick(){

//This function fires on Tab Click;

//Write your code

}

Hope it helps 🙂