Hide/Show a workflow rule field based on a checkbox

SOLVED

I am trying to hide or show a date and time field based on a checkbox being ticked or not. Currently, I have the below script in OnChange for the checkbox, but it only removes the date box, not the caption or the time box. 

if (crm('oppo_aftercarecall').val() == false)
{
oppo_aftercarecalldate.style.visibility = 'hidden';
}
else
{
oppo_aftercarecalldate.style.visibility = 'visible';
}

The other problem with this is that it doesn't hide the date/time field by default when the checkbox isn't ticked. 

Can anyone suggest the best way to achieve this in CRM 2018 R3?

Parents
  • +1
    verified answer

    Try this in the custom content surrounded by script tags

    function aftercareCall() 
    {
    if (crm.fields("oppo_aftercarecall").val() == true) 
    {
    crm.fields("oppo_aftercarecalldate").show();
    } 
    else 
    {
    crm.fields("oppo_aftercarecalldate").hide();
    }
    }
    crm.ready(function() 
    {
    aftercareCall();
    });

    Then place aftercareCall(); in the onchange box of the oppo_aftercarecall field

Reply
  • +1
    verified answer

    Try this in the custom content surrounded by script tags

    function aftercareCall() 
    {
    if (crm.fields("oppo_aftercarecall").val() == true) 
    {
    crm.fields("oppo_aftercarecalldate").show();
    } 
    else 
    {
    crm.fields("oppo_aftercarecalldate").hide();
    }
    }
    crm.ready(function() 
    {
    aftercareCall();
    });

    Then place aftercareCall(); in the onchange box of the oppo_aftercarecall field

Children