Hide Cost Centre & Department Fields from Nominal List dynamically

SOLVED

Hi all,

I would like to force hide the cost center & department fields from Nominal List. unticking it from the columns list will not be acceptable as user can still tick it and display the fields. Any idea maybe by using code or anything?

Thank you.

  • 0

    Create your own class which inherits from Sage.Desktop.Lists.NominalLedgerDesktopListForm. Override GetColumnsProtected(), and in your method get the List<ListColumn> collection from the base class then just remove the ones you don't want. Package that up into an SDBX with its own defined feature and then swap out the desktop list in your client's system for your version.

  • 0 in reply to Chris Burke

    Thank you I will try it out.

    Any idea how to hide the column inside the search popup? this popup is using Sage.MMS.Controls.NominalPopupList2 which inherit PopupTextBox, so there is no columns variable.  

  • 0 in reply to murni

    I can only think of doing something like this:

    var nominalLookup = (Sage.MMS.Controls.NominalLookup2)_form.FindControlByName("nominalLookup").UnderlyingControl;
    
    FieldInfo fi = nominalLookup.GetType().GetField("referencePopupListTextBox", 
    BindingFlags.Instance | BindingFlags.NonPublic);
    
    var referencePopupListTextBox = (Sage.MMS.Controls.NominalPopupList2)fi.GetValue(nominalLookup);
    
    referencePopupListTextBox.PopupOpened += (s, e) =>
    {
    if (e.Form != null && e.Form is Sage.MMS.Controls.NominalListForm listForm)
    {
    Type listFormType = listForm.GetType();
    foreach (string colName in new string[] { "_oCostCentre", "_oDepartment" })
    {
    fi = listFormType.GetField(colName, BindingFlags.Instance | BindingFlags.NonPublic);
    var column = (Sage.ObjectStore.Controls.ListColumn)fi.GetValue(listForm);
    column.Width = 0;
    column.Visible = false;
    }
    }
    };

  • 0 in reply to Chris Burke

    that works! Thank you Chris.

  • 0 in reply to Chris Burke

    my class successfully called to sage 200. but not showing anything on the list whether I remove columns or not. 

    Its not showing columns header as well.

  • +1 in reply to murni
    verified answer

    I don't think what you're doing there is going to work because the call to base.GetColumnsProtected() will constantly rebuild the collection.

    That said, I realised that modifying the columns collection is only part of the job. The desktop list builds the context menu by looking at the field descriptors of the datasource; so it'll rebuild that collection every time - and your user will still be able to add the column.  Here's a better solution. 

    public partial class NominalListDesktop : Sage.Desktop.Lists.NominalLedgerDesktopListForm
        {
            protected override List<ListColumn> GetColumnsProtected()
            {
                List<ListColumn> _columns = new List<ListColumn>();
                foreach (ListColumn listColumn in base.GetColumnsProtected())
                {
                    if (listColumn.DisplayMember == "AccountCostCentre" || 
                        listColumn.DisplayMember == "AccountDepartment")
                    {
                        continue;
                    }
                    _columns.Add(listColumn);
                }
                return _columns;
            }
    
            protected override PersistentObjectCollection GetSourceDataProtected()
            {
                NominalAccountViews views = (NominalAccountViews)base.GetSourceDataProtected();
                IPersistentObject owner = views.Owner;
                foreach (Sage.ObjectStore.Builder.FieldDescriptor fieldDescriptor 
                    in owner.MetaData.FieldDescriptors)
                {
                    if (fieldDescriptor.FriendlyName == "CC" 
                        || fieldDescriptor.FriendlyName == "Dept.")
                    {
                        fieldDescriptor.IsBrowsable = false;
                        fieldDescriptor.IsQueryable = false;
                    }
                }
                return views;
            }       
        }

  • 0 in reply to Chris Burke

    Thank you Chris. That works!