Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Hide Copy Button- ValueList Option

PrathameshYedav
Collaborator II

Hello Team,

I need your help to on below mentioned scenario.

 

I want to hide COPY button when value list option A ,B,C or D selected.

For other options COPY button should be there.

 

I have written below code:

 

<script type="text/javascript">
var valuesListFieldId = 22875; // This is the field id of the values list
var valuesListValueId = 77972; // This is the id of the value to check against
var valuesListValueId = 77973; // This is the id of the value to check against
var valuesListValueId = 77971; // This is the id of the value to check against
var valuesListValueId = 77970; // This is the id of the value to check against
var valuesListValue;

Sys.Application.add_load( function() {
valuesListValue=$('div[id*="f' + valuesListFieldId +'c"] div:last').attr('data-valueslistvalueid');

if(valuesListValue == valuesListValueId) {
$('#master_btnCopy').hide();
}
});
</script>

 

But this code is only working when  'var valuesListValueId = 77970; ' only option D is getting selected.

For other selection, COPY is enabled.

 

David Petty‌ Ilya Khen

 

 

20 REPLIES 20

Ilya_Khen
Champion III

Try this one. A bit dirty, and better to use loo/break structure:

var valuesListFieldId = 22875; // This is the field id of the values list
var valuesListValueAId = 77972; // This is the id of the value to check against
var valuesListValueBId = 77973; // This is the id of the value to check against
var valuesListValueCId = 77971; // This is the id of the value to check against
var valuesListValueDId = 77970; // This is the id of the value to check against
var valuesListValue;

Sys.Application.add_load(function() {
    valuesListValue = $('div[id*="f' + valuesListFieldId + 'c"] div:last').attr('data-valueslistvalueid');

    if (valuesListValue == valuesListValueAId || valuesListValue == valuesListValueBId || valuesListValue == valuesListValueCId || valuesListValue == valuesListValueDId) {
        $('#master_btnCopy').hide();
    }
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

Code above would work in case you use Dropdown type of VL, plus during the record load only, not when VL is changed.

GeoffTaylor2
Contributor III

In this part of the code:

 

var valuesListValueId = 77972;
var valuesListValueId = 77973;
var valuesListValueId = 77971;
var valuesListValueId = 77970;

 

... You're using the same variable name each time, so the variable is set to the value in the last statement (77970). This is why it works with D but not the others. You would need to use different variable names, or an array with a loop.

Good catch Geoff

 

Prathamesh see how this work.

<script type="text/javascript">
     var valuesListFieldId = [22875,77972,77973,77971,77970];

     Sys.Application.add_load( function() {
          for(var v=0; v<valuesListFieldId.length; ++v){
               if($CM_getFieldValue(valuesListFieldId[v]) != null) { // Looking to see if the values list value isn't null
                    $('#master_btnCopy').hide();
                    break;
               }
          }
     });
</script>
‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant

That is what I call - quality code  Thanks, David!

This is only working when record is in view mode. Upon editing the record, copy button is coming back. Same in 5.5 or in 6.3. Any Idea to fix it. David's below code is not working.

Chatterjee, do you have the Display option for the custom object set to Both?

 Advisory Consultant

David's code should work for sure as it it getting values from internal library.

Yes David. Display option is set to Both.

Can you post the code you're using in the custom object?

 Advisory Consultant