Show both active and inactive records in the lookup view

CRM MVP Batistuta Cai already had a post about a plug-in solution.

If the lookup entity is a system entity, you can also use this technique:

Let’s start from an example: you have a custom entity call: MyEntity, you have setup a N:1 relationship between MyEntity and Opportunity, so the user can see an opportunity lookup field on the MyEntity form. Now you want to show users both active and inactive opportunities from that lookup field, all you need to do is put the below code into MyEntity.OnLoad() event:

crmForm.all.new_opportunityid.lookupclass = “alllookups”;

The lookup class are controlled via xml files in %ProgramFiles%\Microsoft CRM\Server\ApplicationFiles\
If you take a look at the file: opportunity.xml, you may find a condition like: <condition attribute=”statecode” operator=”eq” value=”0″/>

you can remove the condition, and then use this class, e.g: crmForm.all.new_opportunityid.lookupclass=”opportunity”; However it’s very much unsupported way(by changing files)! But if you open the file: alllookups.xml, you may find that the opportunity(object type=”3″) entity doesn’t have such condition, so we can use this class to get all opportunities.

Set Field Required Dynamically – Using JScript for CRM 4.0

switch (parseInt(event.srcElement.DataValue, 10))


/* Opportunity Rating Picklist */

case 1:

/* Hot */

crmForm.SetFieldReqLevel(“pricelevelid”, 1);

crmForm.SetFieldReqLevel(“estimatedvalue”, 1);

crmForm.SetFieldReqLevel(“estimatedclosedate”, 1);

crmForm.SetFieldReqLevel(“closeprobability”, 1);


case 2:

/* Warm */

crmForm.SetFieldReqLevel(“pricelevelid”, 1);

crmForm.SetFieldReqLevel(“estimatedvalue”, 0);

crmForm.SetFieldReqLevel(“estimatedclosedate”, 1);

crmForm.SetFieldReqLevel(“closeprobability”, 0);


case 3:

/* Cold */

crmForm.SetFieldReqLevel(“pricelevelid”, 0);

crmForm.SetFieldReqLevel(“estimatedvalue”, 0);

crmForm.SetFieldReqLevel(“estimatedclosedate”, 0);

crmForm.SetFieldReqLevel(“closeprobability”, 0);


/* All other values */


crmForm.SetFieldReqLevel(“name”, 0);

crmForm.SetFieldReqLevel(“customerid”, 0);



Replace a field to a button or Create a button on Form, and attach the onclick() event

This is an example on how to create a button on the form, using java script. First of all we need to create a nvarchar attribute and put it on the form where we want our button.
In this example my attribute’s schema name is new_test.

Here is the code


someFunction = function()


alert(“button clicked!”);


// This is how we call the button, what we see

crmForm.all.new_test.DataValue = “Button”;

// We could align it a bit = “center”;

crmForm.all.new_test.vAlign = “middle”;

//we make the mouse look as a hand when we’re moving over = “hand”; = “#CADFFC”; = “#FF0000”; = “#330066”; = “bold”;

crmForm.all.new_test.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

Replace a field to a label (use replaceNode())
/* replace new_field_d to a label */
if (crmForm.all.new_field != null)
var html = document.createElement( “”);
html.innerText = “this is a lable”;

Append text under a field (you don’t need to create an attribute for that)
/* append text under new_field */
if(crmForm.all.new_field != null)
var html= document.createElement( “”);
html.innerText = “this is a text field”;

%d bloggers like this: