Tuesday, November 27, 2007

Hide Tabs Script compatible in MSCRM 4.0

One of the things that has been on my mind has been the scripting that has been floating around that modifies DHTML on a CRM form.


One of the more frequent requests that I get and end up in implementing is that of hiding a tab on a form. Below is some code that I have used in MSCRM 3.0 on the Account form to hide the Notes tab from a default set up, but technically, the 4th tab on the form.

Here's the code that I have tested in the beta system I have and my code still worked:

var oType = crmForm.all.address1_addresstypecode;
switch (oType.SelectedText)
{
case "Other":
crmForm.all.tab3Tab.style.visibility = "hidden";
crmForm.all.tab3Tab.style.position = "absolute";
break

default:
crmForm.all.tab3Tab.style.visibility = "visible";
crmForm.all.tab3Tab.style.position = "relative";
break;
}

Now, whenever the option of "Other" is selected from the Address Type field, the Notes tab will disappear.


I'll be testing more scripts to see how much scripting changes I'll be having to make when I upgrade clients to MSCRM 4.0.

David Fronk
Dynamic Methods Inc.

14 comments:

christineJ said...

Hy David
have you been able to test the fetch xml (unsupported - but essential!!!) on look up fields (to restrict choice depending on other field values) in 4.0?
thx
christine

Dynamic Methods said...

I actually have not tested that script just yet. However, my next post will about more scripts that do and don't work in 4.0. I probably won't have the resolution to most of the scripts that don't work just yet but hopefully I'll figure those out soon enough. But the only script that I know of that restricts the Lookup field is the one that restricts the type options to be only one type (Account vs Contact) and that only works when you click on the lookup glass button, not for the Form Assistant. If there are any scripts you would like me to test I'd be happy to try some out for you as long as I can post about them. Email me at davidfronk10@gmail.com.

Thanks,

David Fronk
Dynamic Methods Inc.

Anonymous said...

From Ronald's blog, the great filtered lookup is working
http://ronaldlemmen.blogspot.com/2006/12/filter-data-in-crm-lookup-field.html

But I tried this in CRM 4 RP0 VPC, it does not work.

Do you know what happen?

what a pity CRM 4 not have the function for "filtered lookups"

David will you please have a look.

Andrew
aliu711012@hotmail.com

Dynamic Methods said...

The reason the filtered lookup code doesn't work in 4.0 is because it is using Fetch XML. Fetch XML was supported in version 1.2 but customizations from 1.2 are no longer supported in 4.0. 3.0 supported 1.2 customizations and 4.0 will support 3.0 customizations but not 1.2. When each version comes out you can expect your code from one version back to work with the new version. So, all 1.2 code will need to be updated to work with 3.0 code in order for it to work in 4.0.

I hope that makes sense, but that's why the code doesn't work, it's because Microsoft specifically stated that Fetch XML would no longer work with this version of MSCRM.

David Fronk
Dynamic Methods Inc.

Anonymous said...

Thanks David,

But for CRM 4, is there a way to filter a lookup?

I want to create some linked lookups, such select a contract when create a new case (you only can select a contract under the current customer).

Andrew
aliu711012@hotmail.com

Thanks

Dynamic Methods said...

Andrew,

Unfortunately, to my knowledge, I do not know of a way to do what you are requesting. Now, that's not to say that it's not possible. I haven't played with it much myself but I can bet that this is something that someone will hack out in short order. I have not implemented this for any of my customers so I really haven't played much with this. My guess is that someone that does have this working for a client will be forced to figure it out ASAP. I'll keep my ears open and if I hear anything I'll be sure to post about it. Sorry I couldn't be of more help at the moment.

David Fronk
Dynamic Methods Inc.

christineJ said...

David, that will be great.

maybe its easier to adapt ronald lemmens secondory custom lookup for 4.0 (the code from 3.0 does not work in 4.0, I have tried) and implement fake lookup - an copy values into hidden look up (on change / on save...)

any ideas???
thx
christine

Daniel said...

Has anyone been able to change Ronalds JS script for 4.0 yet?

Dynamic Methods said...

I have not seen anyone who has adapted the lookup data filter that Ronald has posted about in his blog. You may want to comment on his blog and ask him to see if he has figured out a way to do this yet. I'm sure someone will find the new way to do it, I'm just not sure how long it will take.

Now, that being said, let me also state one other thing. With the new Lookups you can type in them and have it search for what you type. Now this is not the exact same functionality that you are looking for but the point is that if you have some kind of naming convention for things it may help you as you search for things in the lookup field. So, the key that I haven't stated very well is that you can type in the field and then hit "enter" and you will get the lookup window we are used to from v1.2 and v3.0, only now when it appears it will have already performed the search on what you typed into the lookup field. So, my theory is that if Microsoft has now built this functionality in it's only a matter of time before we have the ability to customize the Lookup field search much like we customize the Quick Find View. At least, that's my opinion.

I know my band-aid fix doesn't solve your problem and probably only helps with a very limited number of cases so I will continue to keep my ear to the ground in case this is figured out. If you find it please let me know and I would be happy to post it giving credit where credit is due. And rest assured, if I figure this out for myself then I will definitely post about it.

David Fronk
Dynamic Methods Inc.

christineJ said...

hy david,
microsofts feature to type the first letters an get a prefiltered result is very nice, but not the feature we are looking for.
i.e. the customer selects postal code and in a lookup for street he now only gets the streets valid for the selected postal code.
MSfunctionality doesnt please our needs regarding this or other examples.

Even if they will enhance the search window with lookup search filter values, it is not the thing we need, because we need searches depending on a value dynamically selected on the related form (e.g. postal code on contact form) - and not on the lookup entity (e.g. custom entity: street)

we are evaluating michael höhnes custom lookup right now (stunware.com), he is changing functionality to fit for 4.0.

greets
christine

Benjamin Rutledge said...

Can you alter this code for a bit field? Same function, but more of an on/off.

Thanks,
Benjamin Rutledge

Dynamic Methods said...

Benjamin,

Absolutely. You can use whatever logic you want. You just need to change your IF ststement to check the boolean (bit) field instead of the picklist that I used in my example. You could use a text field and check for a certain value or whatever you wanted really.

Good luck,

David Fronk
Dynamic Methods Inc.

Schnugie said...

Hi David

Do you perhaps have some code for hiding/ displaying fields based on teh content of another field? In particular if we have a lookup field (Field A) which does not have a certain value OnLoad then some other fields (Field C,D and E) must be hidden. However when a user changes the content of field A then the OnChange script must display the fields which were originally hidden (C,D,E) so that they can be modified by the user. The next time that the form loads those fields must no longer be hidden. Do you have any clue as to how one could get this right?

Dynamic Methods said...

Schnugie,

Please look at today's post:
http://dmcrm.blogspot.com/2008/07/hiding-fields-and-labels-on-fly-via.html

Hopefully that goes over everything that you need.

David Fronk
Dynamic Methods Inc.

Post a Comment