How to hide a field until a particular source is selected in Opportunity

Hi,

We're trying to hide two fields on the opportunity summary page when creating a new opportunity as well as existing opportunities if the oppo_source isn't a particular value.

So when the oppo_source is 'Delivery Enquiry' we want the Delivery Quantity & Delivery Requirements fields to be displayed.

We've created the fields, added them to the appropriate Opportunity screen. We're using the following in the Custom Content box;

<script>

crm.ready(function () {

crm.fields('oppo_deliveryquantity').hide()

})
</script>

And then in the OnChangeScript for the fields we're using;

crm.fields('oppo_deliveryquantity').show;

However, this isn't working. Can anyone suggest a solution?

  • 0

    Hello

    Show is a method.

    crm.fields('oppo_deliveryquantity').show;

    should be

    crm.fields('oppo_deliveryquantity').show();

  • 0

    Will

    This is a dashed response as I really need to finish something else off. I hope you can follow my reasoning.

    You have the custom content code

    crm.ready(function () {

    crm.fields('oppo_deliveryquantity').hide()

    })

    And the business rule is (I've simplified this)

    Hide a field (oppo_deliveryquantity) on the opportunity summary page when creating a new opportunity or editing an existing opportunity if the oppo_source isn't a particular value.

    The first observation that I would make is that your rule doesn't test the existing field value to see if it is null and therefore should be hidden. It just hides the field anyway.

    Consider something like

    //Custom Content - set Company Status Colour

    crm.ready(function()

    {

    if (crm.fields('oppo_source').value()!="the test value")

    {

    crm.fields('oppo_deliveryquantity').hide();

    }

    })

    Note: I've not tested this, I am just writing something with which you can then experiment.

    The onchange script on the field could be something similar

    if (this.value =='the test value')

    {

    crm.fields('oppo_deliveryquantity').show();

    }

    Note: Make sure that your onchange() script does not use " double quotes for strings as this can cause scripts to be ignored. (They get terminated/broken).

    I hope this helps.

  • 0

    Hi Jeff,

    Thanks for getting back to my query so quickly.

    I've amended the show method to be .show();

    However, this still isn't working the field remains permanently hidden despite clicking change, selecting a new source and saving. Surely it should reveal the field?

  • 0

    Hi Jeff,

    I've experimented with your code above. It's hides the field upon creation of the opportunity but when changing the oppo_source to 'Delivery Enquiry' the field is still not visible.

    We need it to only change for Delivery Enquiry so hiding the field for all other sources is essential.

    Custom Content

    crm.ready(function()

    {

    if (crm.fields('oppo_source').value()!='NULL') (I've changed the 'NULL' to other variants too)

    {

    crm.fields('oppo_deliveryquantity').hide();

    }

    })

    I've tried the following variations in OnChange;

    if (this.value =='NULL')

    {

    crm.fields('oppo_deliveryquantity').show();

    }

    -------------------------

    if (this.value =='--None--')

    {

    crm.fields('oppo_deliveryquantity').show();

    }

    ------------------------

    if (this.value =='Delivery Enquiry')

    {

    crm.fields('oppo_deliveryquantity').show();

    }

    -------------------------


    I never expected this one to work but tried anyway -

    if (crm.fields('oppo_source').value =='Delivery Enquiry')

    {

    crm.fields('oppo_deliveryquantity').show();

    }

  • 0

    Hi,

    Thanks Jeff and Paul for both your input, it's appreciated!

    I've managed to get it working for all the fields we needed hiding unless using a specific source by using;

    crm.ready(function(){

    if (crm("oppo_source").value()== "deliveryenquiry")

    {

    crm.fields('oppo_deliveryquantity').show();

    crm.fields('oppo_deliveryrequirements').show();

    crm.fields('oppo_forecast').show();

    }

    else

    {

    crm.fields('oppo_deliveryquantity').hide();

    crm.fields('oppo_deliveryrequirements').hide();

    crm.fields('oppo_forecast').hide();

    }

    })

  • 0

    You don't need to explicitly test for null since that is just one of the values where oppo_deliveryquantity should be hidden; you do need to test for the specific value which means oppo_deliveryquantity should be visible. You need to test for the field database value, not the caption / translation that appears on screen. So in Jeff's code above you need to replace "the test value" with whatever the code value is corresponding to "Delivery Enquiry" translation in the oppo_source selection list. eg If the code for "Delivery Enquiry" is "DelEnq" then the code would be:

    CustomContent:

    oppo_source OnChange:

    if (this.value =='DelEnq')
    {
    crm.fields('oppo_deliveryquantity').show();
    }
    else
    {
    crm.fields('oppo_deliveryquantity').hide();
    }

    Note that I have added a couple of lines to Jeff's code in the oppo_source OnChange script to hide the oppo_deliveryquantity field if a value other than "Delivery Enquiry" is selected, otherwise it would remain visible if "Delivery Enquiry" was previously selected.