Link to home
Start Free TrialLog in
Avatar of apollo7
apollo7Flag for United States of America

asked on

CRM 2011 Converting Javascript

Hi

I am in the process of converting javascript functions from CRM 4.0 format to CRM 2011 format.  I have a specific onLoad script that I need help with but also would like any links or resources that will assist in converting to the new CRM 2011 formats.

What I want to do is to hide fields with the onLoad function.  In the past, I used:

crmForm.all.new_accountbusunit_c.style.visibility = 'hidden';
crmForm.all.new_accountbusunit_d.style.visibility = 'hidden'

I would like the format for the above script as it should appear in CRM 2011..

Thanks
Avatar of processguru
processguru
Flag of United States of America image

To hide a field use:
Xrm.Page.getControl("new_accountbusunit").setVisible(false);
To show a field use:
Xrm.Page.getControl("new_accountbusunit").setVisible(true);

It's always good practice to check & be sure the field exists on the form first, so I personally would write:
    oControl = Xrm.Page.getControl(sFieldId);
    if (oControl != null) {
        oControl.setVisible(false);
    }

You can find a 4.0 to 2011 conversion tool here:
http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCkQFjAA&url=http%3A%2F%2Fcrm2011scriptconvert.codeplex.com%2F&ei=KNHLTr75O4Lo0QGg7o0J&usg=AFQjCNFjlhnag-hOJJLkGrUvPgAJu_jw4w&sig2=K9ddd6wPWp1gmcBOftOGwQ

but this will only work with code that was supported in 4.0. Otherwise reference the SDK documentation:
http://msdn.microsoft.com/en-us/library/gg328255.aspx
Avatar of apollo7

ASKER

Thanks - that worked and hides the field.  However, it leaves a blank area on the form.  In CRM 4.0 there was a way to hide a field and also not have an empty space where the field is located.

Is there a way to remove the blank space left by the hidden field in CRM 2011?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of processguru
processguru
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of apollo7

ASKER

Thanks - I will give this a try.  Also in the future, the field (section) that is hidden will need to be made visible based on a value in an option set.

Will unhiding the section (using a specific option set value) work the same as unhiding the field?

Thanks
Absolutely

.setVisible(true)
Avatar of apollo7

ASKER

Thanks - that makes sense.

The trick seems to be how to format a form with several hidden fields (aka sections) that will be made visible by other fields on the same form.  It doesnt seem like you can embed sections within a section (to keep these fields together).

So, it looks like I will need a form with several sections. If there is any other method, please let me know.

Thanks.
Avatar of Chinmay Patel
Hi apollo7,

How urgently you need this feature?

Regards,
Chinmay.
Avatar of apollo7

ASKER

I am building a single form right now and need a number of fields that disappear onload and become visible when an option set value equals a specific value.  Need to have done this week.

Just curious, what would your approach be?

Thanks
:D... you know.. some hacking and slashing. I got some free time on hand today, let me see what I can do.

Regards,
Chinmay.
Avatar of apollo7

ASKER

@processguru:

The code to hide the section works great.  I am trying to now make the section visible based on a value in another field that is an option set.

Can you give the syntax of the javascript that would precede ".setVisible(true)" for an option set?
Specifically, the option set value of "Yes" would should set the section to visible.

Thanks

 
Avatar of apollo7

ASKER

Everything worked out well, I am able to hide and unhide the fields and sections, thanks
Glad everything worked out. Sorry for not seeing your comment and responding - Holidays and all of that! :)