web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Sales forum / Show or hide Fields on...
Sales forum

Show or hide Fields on entity form on dynamics 365 portals

(1) ShareShare
ReportReport
Posted on by 1,257

Hello all,

I'm trying to show a couple of fields on a entity form on Dynamics 365 portals based on the onChange event of a OptionSet field, the fields are hide on the dynamics 365 form, but on the portal entity form i paste the following JQuery to try to achieve the goal, but no luck yet... T_T

$(document).ready(function() {

  $("#fieldOnChange").change(onStatusChange);
  $("#fieldOnChange").change();
});


function onStatusChange(){
    if ($('#fieldOnChange').val() == "1")
	{
		$('#FieldtoShow_1').show();
		$('#FieldtoShow_2').show();
		
	}else if($('#fieldOnChange').val() == "2")
	{
		$('#FieldtoShow_1').show();
		$('#FieldtoShow_2').hide();

	}else if($('#fieldOnChange').val() == "0")
	{
		$('#FieldtoShow_1').hide();
		$('#FieldtoShow_2').hide();
	}
}
   

Im not sure if i'm missing something else, but i tried pasting it on the Dynamics 365 form and add it to the field just like a normal JS, i tried to pas te it on the entity form of the portal and also on the web page.... and nothing happens! :( any clue for me to reach this out?

In advance so many thanks, Muchas Gracias!

Categories:
I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    The code which you have mentioned seems correct. Possible reason could be that either the id's are not correct, or the value for your optionset is not correct (use alert to confirm this)  or you are not hiding the correct element.

    It is also possible that the method is not getting called, try a simple alert and see if that works. Remove this line $("#fieldOnChange").change();

    Try something like this-

    ===============================

    $('#FieldtoShow_2').parent().hide();

    or

    $('#FieldtoShow_2').parent().parent().hide();

    It all depends upon how the field is getting render on browser i.e. if it is under td/ tr/ dive or something else.

    ===============================

    Refer these:

    community.dynamics.com/.../292094

    community.dynamics.com/.../293326

    Hope this helps.

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    It seems that you didn't catch the right control.

    I suggest that you could press F12 to open developer tool and debug your code to check the two points.

    1.If  $('#fieldOnChange') has valid value.

    2.If  $('#FieldtoShow_1/2') has hide function.

    Hope it helps.

    Best Regards

    Leo

  • Vile Andreas Rantala Profile Picture
    1,257 on at

    But there's no other place to set or instance the code right? just putting it on the custom javascript section, will works, right?

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi,

    Fields can be comprised of multiple elements, so just using the field name to hide it from the portal usually is not enough. As most fields are using tr elements, you can use the following code:

    function setFieldDisplay(fieldName, displayStatus) {

       if (displayStatus == "show") {

           $("#" + fieldName).closest("tr").show()

       }

       else if (displayStatus == "hide") {

           $("#" + fieldName).closest("tr").hide()

       }

    }

    You would call the code as follows:

    setFieldDisplay("FieldtoShow_1", "show") or setFieldDisplay("FieldtoShow_1", "hide")

    You can of course modify that function to fit your needs, and the way that you fields are being displayed.

    Hope this helps.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Yes, you can write JS on wither the entity form or directly to webpage.

  • Vile Andreas Rantala Profile Picture
    1,257 on at

    So many thanks for help! i make it works with the following structure:

    1. don't hide the fields on the CRM form, just hide them with JS on webpage.

    2. hide the TR to do not display the label, with my code just hide the field, but with @Aric comments with "tr" i achieve to hide the field and the label.

  • Nirmal_CRM Profile Picture
    177 on at

    Hi,

    Can you please let me know how did you keep field hidden by default ? 

    Regards,

    Nirmal

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Nirmal,

    On form editor, if you uncheck the property "display by default" then it will not be visible on portal as well

  • Suggested answer
    M.Anas Profile Picture
    35 on at

    Is there any out of the box solution like business rule?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Sales

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans