Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, February 5, 2009

Hiding Locked Fields (and hiding tabs)

It's been well posted about hiding fields and tabs using javascript:
Hiding the 2nd tab can be done with js in the onload event:
crmForm.all.tab1Tab.style.display = 'none';

Hiding a field (must know the field ID):
crmForm.all.FIELDID.style.display = 'none';

I did a bunch of this for various reasons including getting fields to conditionally appear/disappear, hiding tabs that can't be removed for some reason (but are of no use to the implementation) and so forth.

At one point I needed the "Price Per Unit" field. It's locked on the form and the only way I could see to hide it was with javascript. The field hid well, but then I couldn't remove the "$". It was an element called "priceperunit_sys". I tried lots of things, then decided to move it to a new tab and simply hide the tab.

I realized this was a MUCH BETTER solution than hiding each field individually. In this way, I now have a "Hidden" tab that holds all the fields I don't want to display to my users. The advantage is that if I (or anyone else) needs to bring the fields back, they don't need to muck around in the code. They simply move them to a visible tab.

Of course...most fields can be removed, some you may just want hidden because they're used for calculations and may never be shown, but I just stumbled across this and wanted to share.

Friday, July 11, 2008

Pre-Filter Lookup

I ran across some code today that will pre-filter a lookup field based on a selection in another lookup field.

Put this in the onChange of the first lookup:

document.filterLookup(crmForm.all.customerid, crmForm.all.contactid);

Put this in the onLoad of the form:

// Filtered lookup
document.filterLookup = function (source, target) {
if (IsNull(source) IsNull(target)) {
return;
}
var name = IsNull(source.DataValue) ? '' : source.DataValue[0].name;
target.additionalparams = 'search=' + name;
}


For a more in-depth method of achieving this, visit this blog: http://jianwang.blogspot.com/2008/05/mysterious-crm-lookup-ii.html

Monday, June 2, 2008

Hiding Action Menu items

Well, this is completely unsupported but we had to hide the Activate and Deactivate choices from the Actions menu on a form the other day. I highly suggest downloading the IE Developer Toolbar to accomplish this. It will assist with getting the ids for these two menu choices. Here is the javascript we implemented:

//HIDE DEACTIVATE AND ACTIVATE MENU ITEM if (document.all._MIchangeStatedeactivate100145 != null) { document.all._MIchangeStatedeactivate100145.style.display = "none";} if (document.all._MIchangeStateactivate100146 != null) { document.all._MIchangeStateactivate100146.style.display = "none";}

Thursday, March 20, 2008

Disable all attributes on a form

I found this snippet of code today on a message board to disable all attributes on a form:

for (var i = 0; i <>)
{
crmForm.all[i].Disabled = true;
}

Original post can be found here:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.crm.developer&tid=0ddb6aa6-3d3c-4299-835e-94a8bc9509c1

Thursday, September 6, 2007

Getting values from a lookup control

We recently needed to capture both the GUID and the text value from a CRM lookup control. I found some quick code to do this on the following newsgroup:

http://groups.google.com/group/microsoft.public.crm/browse_thread/thread/9bc6721768f0a1f1/4b5f5d0ff5972dc0?lnk=st&q=ms+crm+get+lookup+datavalue&rnum=1&hl=en#4b5f5d0ff5972dc0



var lookupItem = new Array;

lookupItem = crmForm.all.primarycontactid.DataValue;

if (lookupItem[0] != null)
{
// The text value of the lookup.
alert(lookupItem[0].name);


// The GUID of the lookup.
alert(lookupItem[0].id);
}


Thursday, May 3, 2007

Hiding and Disabling CRM fields with Javascript

I always forget the syntax for hiding and disabling fields in CRM. Below are some common examples:

//hide contract and contract line fields
crmForm.all.contractid_d.style.visibility = 'hidden';
crmForm.all.contractdetailid_d.style.visibility = 'hidden';


//hide a tab
crmForm.all.tab3Tab.visibility = "hidden";

//disable lookup fields
var oField = crmForm.all.SOME_FIELD_ID;
oField.Disabled = !oField.Disabled;


//disable radio button field
crmForm.all.new_inboundoutbound.disabled = true;

//disable datetime field
if(crmForm.FormType!=4)
{
//disable data field
var oField = crmForm.all.new_resolutiondate;
oField.Disabled = !oField.Disabled;
}

Wednesday, May 2, 2007

Calling a Workflow Rule from a button

Here's a handy bit of code for calling a Workflow rule from a custom button in CRM. Put the code below into the Page_Load handler of an aspx page. In this example I call the aspx page and pass an Account record GUID (accountId) which is fed into the workflow rule.

// CRM Service Setup
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.Url = "http://server/mscrmservices/2006/crmservice.asmx";


// Setup the request
string accountId;
accountId = Request.QueryString["accountId"];
ExecuteWFProcessRequest request = new ExecuteWFProcessRequest();


// Triggers Workflow process
request.ProcessId = new Guid("{E4206735-0379-4DE5-A453-AC7A7DA1462B}");
request.EntityMoniker = new Moniker();
request.EntityMoniker.Id = new Guid(accountId);
request.EntityMoniker.Name = EntityName.account.ToString();


// Execute the request
ExecuteWFProcessResponse response = (ExecuteWFProcessResponse) service.Execute(request);