Friday, 19 July 2019

tree lookup for reference group d365

//class declreation
EcoResCategoryHierarchy         procurementCategoryHierarchy;
SalesTableForm                  salesTableForm;

//form init
public void init()
    {
        super();
        procurementCategoryHierarchy    = EcoResCategoryHierarchy::find(EcoResCategoryHierarchyRole::getHierarchiesByRole(EcoResCategoryNamedHierarchyRole::Procurement).CategoryHierarchy);
        salesTableForm                  = SalesTableForm::construct(SalesTableFormId::None, element.args().record());
    }

//field methods under datasource
[DataField]
        class ProcurementCategoryId
        {
            public Common lookupReference(FormReferenceControl _formReferenceControl)
            {
                Common ret;
                   
                ret = EcoResCategory::lookupCategoryHierarchy(
                        _formReferenceControl,
                        procurementCategoryHierarchy,
                        false,
                        true,
                        true,
                        null,
                        CompanyInfo::find().RecId,//purchReqLine.BuyingLegalEntity,
                        CompanyInfo::find().RecId//purchReqLine.ReceivingOperatingUnit
                    );
                   
                return ret;
            }

            public Common resolveReference(FormReferenceControl _formReferenceControl)
            {
                Common ret;
           
                ret = EcoResCategory::resolveCategoryHierarchy(
                        _formReferenceControl,
                        procurementCategoryHierarchy,
                        false,
                        true,
                        true
                    );
           
                return ret.RecId? ret : null;
            }

        }

//Item modified
public void modified()
{
EcoResProductCategory       ecoresCatergory;
InventTable                 inventTable;
super();
select inventTable
join ecoresCatergory
where inventTable.ItemId ==  INTC_MaterialTakeOffTable.ItemId
&& ecoresCatergory.Product ==  inventTable.Product;

INTC_MaterialTakeOffTable.ProcureCategoryRecId    =   ecoresCatergory.Category;
}

No comments:

Post a Comment