Tenant Selector In Acumatica

Hi All,

Quick trick for you. If you need to link several tenants together, you can use the code from this article

Tenant selector attribute:

#region NeuralCompanySelectorAttribute
public class CompanySelectorAttribute : PXCustomSelectorAttribute
{
    public CompanySelectorAttribute()
        : base(typeof(UPCompany.companyID))
    {
        DescriptionField = typeof(UPCompany.loginName);
    }

    protected virtual IEnumerable GetRecords()
    {
        PXCache cache = _Graph.Caches[typeof(UPCompany)];
        Int32 current = PX.Data.Update.PXInstanceHelper.CurrentCompany;

        foreach (UPCompany info in PXCompanyHelper.SelectCompanies(PXCompanySelectOptions.Visible))
        {
            if (current != info.CompanyID) yield return info;
        }
    }
    public override void DescriptionFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, string alias)
    {
        if (e.Row == null || (sender.GetValue(e.Row, _FieldOrdinal) == null)) base.DescriptionFieldSelecting(sender, e, alias);
        else
        {
            UPCompany item = null;
            Object value = sender.GetValue(e.Row, _FieldOrdinal);
            Int32 key = (Int32)value;
            foreach (UPCompany info in PXCompanyHelper.SelectCompanies())
            {
                if (info.CompanyID == key)
                {
                    item = info;
                    break;
                }
            }
            if (item != null) e.ReturnValue = sender.Graph.Caches[_Type].GetValue(item, _DescriptionField.Name);
        }
    }
}
#endregion

Attribute usage:

public class BaseProject : IBqlTable
{
    #region BaseCompanyID
    [PXInt()]
    [PXUIField(DisplayName = "Base Company ID", Required = true)]
    [CompanySelector()]
    [PXDefault]
    public virtual int? BaseCompanyID { get; set; }
    public abstract class baseCompanyID : IBqlField { }
    #endregion
}

 

This trick can be usefull if you have Inter-Tenants reports like here.

Have a nice development!

Leave a Reply

Please rate*

Your email address will not be published. Required fields are marked *