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

cancel
Showing results for 
Search instead for 
Did you mean: 
100% helpful (6/6)
DavidPetty
Archer Employee
Archer Employee

The following custom object will hide the 'Add New' link for specific cross-reference fields.

 

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

     Sys.Application.add_load(function (){
          var crossReferenceToHideAddNew = getFieldId(['Cross-Reference Field A', 'Cross-Reference Field B']);
          if (debugging) console.log(crossReferenceToHideAddNew);

          $.each(crossReferenceToHideAddNew, function(key, value){
               if(value.id != 0) {
                    control = $find($CM.getFieldById(value.id).clientId);
                    if (debugging) console.log('Control: ' + control);

                    if(control) {
                         var namingContainer = control._namingContainer;
                         if (debugging) console.log('Naming container: ' + namingContainer);
                         switch(control._displayControlType) {
                              case 'Grid':
                                   if (debugging) console.log('Cross-reference is grid display');
                                   if($('#'+namingContainer).find('.add-new').length >0) {
                                        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;');
                                   } else {
                                        if (debugging) console.log('     User doesn\'t have access to create records');
                                   }
                                   break;
                              case 'SingleColumn':
                                   if (debugging) console.log('Cross-reference is single-column display');
                                   if($('#'+control._referenceFieldId+'_Add_New').length >0) {
                                        if (getStyle('#' + $('#'+control._referenceFieldId+'_Add_New')[0].id) == '') document.styleSheets[2].addRule('#' + $('#'+control._referenceFieldId+'_Add_New')[0].id, 'display: none !important;');
                                   } else {
                                        if (debugging) console.log('     User doesn\'t have access to create records');
                                   }
                                   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>

 

How To Use

Update the crossReferenceToHideAddNew varible with the field names of the cross-reference field(s) you want to hide the 'Add New' link.

Archer Version Supported

  • 6.8+
  • 6.9+

Support

If you have any issues with this custom object, feel free to create a Discussion in the Archer Custom Objects - RSA Link  sub-community or post your comment below.

There is dubugging information the script will output.  Change the debugging variable value from false to true and use the browsers developer tools console to see the output.

 

History

Version Date Notes
1.0 07/27/2021 Initial release.

 

Was this article helpful? Yes No
Version history
Last update:
‎2021-07-27 11:01 AM
Updated by: