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

cancel
Showing results for 
Search instead for 
Did you mean: 

Broken Hide New Custom Object on Cross Reference Fields

JasmineWright
Collaborator III

When upgrading from version 6.5 to 6.8, we noticed that all of our custom objects we created to Hide the Add New button on a cross-referenced field no longer worked; instead of hiding the Add New button, it hid the Add New and Lookup buttons............and users need the Lookup button in these areas.  I believe it has something to do with the significant user interface change introduced.  While we can control this through access (i.e. remove someone's ability to create a Contact record), we need people to be able to create new Contact records for some areas (i.e. when they need to add new vendor contacts) but not others (adding employees).

 

Can someone help me figure out how to update the following custom object code so that it continues to show the Lookup button but hide the Add New button on a cross referenced field?

 

Here's an example of the current code from our Hide Add New custom object in our Emergency Notifications and Call Trees application that  hides the Add New button on our Call Initiator and Call Recipients cross referenced field:

<script type="text/javascript">

var xrefFieldIds= [13513,13515];

var sectionId, clientId;

 

Sys.Application.add_load(function() {

$.each(xrefFieldIds,function(i,v){

sectionId = $CM._fields.sectionId;

clientId = $LM._sections[sectionId].clientId;

 

if($('a[id*="'+ v +'c_Add_New"]').length){

$('a[id*="'+ v +'c_Add_New"]').hide();

} else if($('a[id*="'+ clientId +'_Add_New"]').length) {

$('a[id*="'+ clientId +'_Add_New"]').hide();

$('a[id*="'+ clientId +'_Add_New"]').next().hide();

} else if ($('a[id*="'+ clientId + '_ss' + v + '_Add_New"]').length) {

$('a[id*="'+ clientId + '_ss' + v + '_Add_New"]').hide();

$('a[id*="'+ clientId + '_ss' + v + '_Add_New"]').next().hide();

}

});

});

</script>

3 REPLIES 3

DavidPetty
Archer Employee
Archer Employee

Jasmine, see how this version works.

 

On line 6, add the field names you want the hide the Add New link.

<script type="text/javascript">
     var debugging = true;

     Sys.Application.add_load(function (){
          var crossReferenceToHideAddNew = getFieldId(['Control Standards (Grid)', 'Control Standards (Grid Own Section)', 'Control Standard (Single-Column)']);

          $.each(crossReferenceToHideAddNew, function(key, value){
               if(value.id != 0) {
                    control = $find($CM.getFieldById(value.id).clientId);

                    if(control) {
                         var namingContainer = control._namingContainer;
                         switch(control._displayControlType) {
                              case 'Grid':
                                   if (getStyle('#' + $('#'+namingContainer).find('.add-new')[0].id) == '') document.styleSheets[2].addRule('#' + $('#'+namingContainer).find('.add-new')[0].id, 'display: none !important;');
                                   if (getStyle($('#' + $('#'+namingContainer).find('.add-new').parent()[0].id + '> span:first-of-type')) == '') document.styleSheets[2].addRule('#' + $('#'+namingContainer).find('.add-new').parent()[0].id + '> span:first-of-type' , 'display: none !important;');
                                   break;
                              case 'SingleColumn':
                                   if (getStyle('#' + $('#'+control._referenceFieldId+'_Add_New')[0].id) == '') document.styleSheets[2].addRule('#' + $('#'+control._referenceFieldId+'_Add_New')[0].id, 'display: none !important;');
                                   break;
                         }
                    }
               } else {
                    if (debugging) console.log('Couldn\'t find field, ' + key);
               }
          });
     });

     function getFieldId(fld){
          var layoutId;

          if (typeof fld == 'string' || fld instanceof String) {
               return lookupFieldId(fld)
          } else if (fld.constructor === Array) {
               var fieldDefinitions = {};
               $.each(fld, function(index,value){
                    layoutId = lookupFieldId(value);
                    layoutId != 0 ? fieldDefinitions[value] = {'id': layoutId} : fieldDefinitions[value] = {'id': 0};
               });
               return fieldDefinitions;
          }
     }

     function lookupFieldId(fldName){
          var goFindId = null;
          try{
               $('.FieldLabel').each(function(){
                    if($(this).text().indexOf(fldName + ':') != -1){
                         goFindId = $(this).find("span")[0].id;
                         return false;
                    }
               });
          } catch (err) {}
          try {if (!goFindId) goFindId = $('.SectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}
          try {if (!goFindId) goFindId = $('.SubSectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}

          return goFindId ? $LM._layoutItems[goFindId.replace( /^\D+/g, '')].fieldId : 0;
     }

     $.expr[':'].findField = function(a, i, m) {
          return $(a).text().replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_').match("^" + m[3].replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_') + "$");
     };

    function getStyle(className) {
          var cssText = "";
          var classes = document.styleSheets[2].rules || document.styleSheets[2].cssRules;
          for (var x = 0; x < classes.length; x++) {
               if (classes[x].selectorText == className) {
                    cssText += classes[x].cssText || classes[x].style.cssText;
               }
          }
          return cssText;
     }
</script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant

@DavidPetty  I implemented this in our Archer 6.9 SP1 P5 and it works fine in IE 11, but when I validated in Chrome (almost all end-users are using Chrome) the record load hangs and is never displayed. Is there an incompatibility issue with Chrome?

**UPDATE** I changed the default Display selection from "Both" to "Edit Mode" and it seems to be working fine now. Not sure if this was a true fix, a coincidence or a timing issue, but it seems to be working now.

Ajeet
Contributor III

If we need to hide only lookup instead of Add new so what code needs to be applied or what changes needs to be done in this code?