Friday, March 28, 2014

Custom Lookup in Enterprise Portal

We can using AX query to build the custom lookup function in Enterprise Portal. Here is a example on Expense type in Expense Report.
  
protected void CostType_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup lookup = e.LookupControl;

        using (Proxy.SysDataSetBuilder sysDataSetBuilder =
            Proxy.SysDataSetBuilder.constructLookupDataSet(
                this.AxSession.AxaptaAdapter, TableMetadata.TableNum("TrvCostType")))
        {
            lookup.LookupDataSet = new DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
        }

        using (Proxy.Query query = lookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
        {
            Proxy.QueryBuildRange categoryRange = query.dataSourceNo(1).addRange(TableDataFieldMetadata.FieldNum("TrvCostType", "IsInactive"));
            categoryRange.value = "0";
            categoryRange.status = (int)Proxy.RangeStatus.Hidden;
        }

        AxBoundField costTypeBoundField = AxBoundFieldFactory.Create(lookup.LookupDataSetViewMetadata.ViewFields["CostType"]);
        costTypeBoundField.SortExpression = "CostType";
        lookup.Fields.Add(costTypeBoundField);

        AxBoundField costTxtDateBoundField = AxBoundFieldFactory.Create(lookup.LookupDataSetViewMetadata.ViewFields["CostTxt"]);
        costTxtDateBoundField.SortExpression = "CostTxt";
        lookup.Fields.Add(costTxtDateBoundField);

        lookup.SelectField = "CostType";
    }


And also, we have to call the lookup method in Web Control.