Set Oppo_Targetclose readonly if another checkbox fiels is not checked in a Workflow rule ?

SUGGESTED

Hi all,

I have setup a New Opportunity workflow rule with a custom field which is a checkbox, and I want the following :

  1. If the user has checked the checkbox field, he can modify the oppo_targetclose date
  2. If the user has not checked the checkbox field, the oppo_targetclose date is readonly, or he can't modify it (there's a default value which is now)

Any suggestion on where and how I could do that ?

Thanks a lot.

  • 0

    In the createscript of the oppo_targetclose on the workflow screen (not the OpportunityDetailBox) you will do something like this:

    if(CRM.GetContextInfo('oppo_mycheckboxfield') != 'Y')
      ReadOnly = true;

  • 0 in reply to Vega

    Thanks Vega, but it can't work like this as the field comes uncheked by default so putting this in the createscript of the checkbox fields always result at setting it readonly :)

  • 0 in reply to PPI-VDM

    Then the requirements aren't correct. If the value is not checked, the target close field is readonly, which is what the script does. If the value is checked, it will fail the condition and won't apply the read only attribute. You only want the user to be able to set the target close date when the checkbox has been ticked.

  • 0 in reply to PPI-VDM

    Hang on, are these fields managed by workflow and in different workflow stages?

  • 0 in reply to Vega

    1. This script must apply in the first workflow rule (the "new opportunity" one)

    2. When I check, the target close is not readonly and can be edited

    3. When I uncheck, the target close becomes readonly

    4. and so on... So it should be dynamic, not static once for all !

  • 0 in reply to Vega

    No, the target close date is only available during the creation of the new opportunity. We don't provide it at later stages.

  • 0 in reply to PPI-VDM

    Oh, so you want it to become readonly or not readonly as the user ticks or unticks the box?

  • 0 in reply to Vega
    SUGGESTED

    It's probably easier to make the target close date disappear than make it readonly. Also, what if they have prefilled it in, and then you uncheck the box? Do you want the value cleared? You can either make the field fade in and out which looks nice on the screen but it removes the elements from the DOM so things can move around if the field is in the middle of others. If you use the hide function it just makes the field hidden but keeps the screen layout correct. In your workflow screen put the script below in the custom content, and then on the onChange event of the tick box, just have setTargetClose(); so it calls the function when you tick/untick the box.

    function setTargetClose()
    {
        if(!crm.fields("comp_optout").val())
        {
            crm.fields("comp_name").val("");
            crm.fields("comp_name").hide();
        }
        else
        {
            crm.fields("comp_name").show();
        }
    }
    
    crm.ready(function()
    {
        setTargetClose();
    });

    Ensure that you have the script tags surrounding the javascript in the custom content. I would have put it in but it means I can't post the code. Obviously you'll need to change the field names as I was testing this on the company summary screen.