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

<script type="text/javascript">
var valuesListFieldId = [20588,73582,73583];

Sys.Application.add_load( function() {
for(var v=0; v<valuesListFieldId.length; ++v){
if($CM_getFieldValue(valuesListFieldId) != null) {
$('#master_btnCopy').hide();
break;
}
}
});
</script>

For Edit mode, I would prefer David's code more. But if you need to work it out with dirty coding, I would look for "div input" combination, use "val()" instead of "attribute".

The code looks fine and a little perplexed on why it works for View mode and not Edit mode.  Typically that's inductive of the Display option not set to Both which you said it is set to Both.

 

I added a console output to see if it's finding a value in edit mode.  Make sure you have the browsers console open before entering the record.

<script type="text/javascript">
     var valuesListFieldId = [20588,73582,73583];
    
     Sys.Application.add_load( function() {
          for(var v=0; v<valuesListFieldId.length; ++v){
               console.log("Values list value is: " + $CM_getFieldValue[v]);
               if($CM_getFieldValue[v] != null) { // Looking to see if the values list value isn't null
                    $('#master_btnCopy').hide();
               }
          }
     });
</script>

 Advisory Consultant

Hi David,

 

My bad. I provided the wrong code which I was testing and was open to me however unfortunately not working either in view or in edit mode. I tested your above code as well but same result. I kept the custom object field display option to both.

 

As mentioned initially, below code is working when record is initially loaded however copy button coming back when i click on edit. Testing now in 5.5 version. Objective is to hide copy for the listed values below and keep it for other values not included in the below code.

 

<script type="text/javascript">
var valuesListFieldId = 19076; // This is the field id of the values list
var valuesListValueAId = 73225; // This is the id of the value to check against
var valuesListValueBId = 73226; // This is the id of the value to check against
var valuesListValueCId = 73227; // 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) {
$('#master_btnCopy').hide();
}
});
</script>

Try something like this:

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 = getValue(valuesListFieldId);

    if (valuesListValue.indexOf(valuesListValueAId) != -1  || valuesListValue.indexOf(valuesListValueBId) != -1 || valuesListValue.indexOf(valuesListValueCId) != -1 || valuesListValue.indexOf(valuesListValueDId) != -1) {
        $('#master_btnCopy').hide();
    }
});

function getValue(fldId) {
     var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(fldId); 
     var RPFieldRootId = RPFieldRoot.clientId;

     return $('input[id*="'+ RPFieldRootId +'"]').val();
}

Hi Ilya, Code is working only in Edit mode now. Display is set to Both and tested in view mode only or edit mode only. In edit mode, it is working . In view mode page scrolling is getting disabled and looks like loading time is slower. .

Make 2 custom objects, one for view mode, another for edit mode. And use different codes there.

Thanks. It managed to work with 2 different code and 2 different display.

 

Edit mode

<script type="text/javascript">
var valuesListFieldId = 19075; // This is the field id of the values list
var valuesListValueAId = 73223; // This is the id of the value to check against
var valuesListValueBId = 73224; // This is the id of the value to check against
var valuesListValue;

Sys.Application.add_load(function() {
valuesListValue = getValue(valuesListFieldId);

if (valuesListValue.indexOf(valuesListValueAId) != -1 || valuesListValue.indexOf(valuesListValueBId) != -1 ) {
$('#master_btnCopy').hide();
}
});
function getValue(fldId) {
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(fldId);
var RPFieldRootId = RPFieldRoot.clientId;

return $('input[id*="'+ RPFieldRootId +'"]').val();
}
</script>


View Mode

<script type="text/javascript">
var valuesListFieldId = 19075; // This is the field id of the values list
var valuesListValueAId = 73223; // This is the id of the value to check against
var valuesListValueBId = 73224; // 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) {
$('#master_btnCopy').hide();
}
});
</script>

Chatterjee, this can be condensed into one custom object with the Display option set to Both.  This way you only have to worry about updating one custom object when packaging across environments.

 

<script type="text/javascript">
     var valuesListFieldId = 19075; // This is the field id of the values list
     var valuesListValueAId = 73223; // This is the id of the value to check against
     var valuesListValueBId = 73224; // This is the id of the value to check against
     var valuesListValue;

     Sys.Application.add_load(function() {
          var recordMode = ArcherTech.UI.GenericContent.GetInstance().get_mode(); // 1 = Edit, 2= View

          if(recordMode == 1){
               valuesListValue = getValue(valuesListFieldId);
          }else if(recordMode == 2) {
               valuesListValue = $('div[id*="f' + valuesListFieldId + 'c"] div:last').attr('data-valueslistvalueid');
          }

          if (valuesListValue.indexOf(valuesListValueAId) != -1 || valuesListValue.indexOf(valuesListValueBId) != -1 ) {
               $('#master_btnCopy').hide();
          }
     });

     function getValue(fldId) {
          var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(fldId);
          var RPFieldRootId = RPFieldRoot.clientId;

          return $('input[id*="'+ RPFieldRootId +'"]').val();
     }
</script>

 Advisory Consultant

I still think it should work without checking the mode by using your code, David.

 

Like I said, I just put some dirty code, which must not be used in a 1st place