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

break;

case 2:

/* Warm */

crmForm.SetFieldReqLevel(“pricelevelid”, 1);

crmForm.SetFieldReqLevel(“estimatedvalue”, 0);

crmForm.SetFieldReqLevel(“estimatedclosedate”, 1);

crmForm.SetFieldReqLevel(“closeprobability”, 0);

break;

case 3:

/* Cold */

crmForm.SetFieldReqLevel(“pricelevelid”, 0);

crmForm.SetFieldReqLevel(“estimatedvalue”, 0);

crmForm.SetFieldReqLevel(“estimatedclosedate”, 0);

crmForm.SetFieldReqLevel(“closeprobability”, 0);

break;

/* All other values */

default:

crmForm.SetFieldReqLevel(“name”, 0);

crmForm.SetFieldReqLevel(“customerid”, 0);

break;

}

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

crmForm.all.new_test.style.textAlign = “center”;

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

//we make the mouse look as a hand when we’re moving over

crmForm.all.new_test.style.cursor = “hand”;

crmForm.all.new_test.style.backgroundColor = “#CADFFC”;

crmForm.all.new_test.style.color = “#FF0000”;

crmForm.all.new_test.style.borderColor = “#330066”;

crmForm.all.new_test.style.fontWeight = “bold”;

crmForm.all.new_test.contentEditable = false;

//we attach some events in order to make it look nice 🙂

crmForm.all.new_test.attachEvent(“onmousedown”,color1);

crmForm.all.new_test.attachEvent(“onmouseup”,color2);

crmForm.all.new_test.attachEvent(“onmouseover”,color3);

crmForm.all.new_test.attachEvent(“onmouseleave”,color4);

function color3() {

crmForm.all.new_test.style.backgroundColor = “#6699FF”;

}

function color4() {

crmForm.all.new_test.style.backgroundColor = “CADFFC”;

}

function color1() {

crmForm.all.new_test.style.color = “000099”;

}

function color2() {

crmForm.all.new_test.style.color = “FF0000”;

}

//here we attach what we want our button do

crmForm.all.new_test.attachEvent(“onclick”,someFunction);
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”;
crmForm.all.new_field_d.replaceNode(buttonText);
}

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”;
crmForm.all.new_field.parentNode.appendChild(html);
}