Look Up form Method

Hi all, Have a clarification on the look up form.

Need to modify the look up method for the Project Purchase Order form for the display of activity number in the drop down. Currently the activity number dropdown appears with the task ID with respect to the project. With the existing method,i need to add a code to bring the values which the HierarchyTreeTable.parentelementnumber != null.

Existing code:

public void lookup(FormControl _formControl, str _filterStr)

{

HierarchyTreeTable::lookupHierarchyTree(_formControl, ProjTable::find(purchLine.ProjId));

}

I modified as

public void lookup(FormControl _formControl, str _filterStr)

{

HierarchyTreeTable::lookupHierarchyTree(_formControl, ProjTable::find(purchLine.ProjId));

Query query = new Query();

QueryBuildDataSource queryBuildDataSource; QueryBuildRange queryBuildRange;

// SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(HierarchyTreeTable), this); HierarchyTreeTable::lookupHierarchyTree(_formControl, ProjTable::find(purchLine.ProjId));

queryBuildDataSource = query.addDataSource(tableNum(HierarchyTreeTable));

queryBuildRange = queryBuildDataSource.addRange(fieldNum(HierarchyTreeTable,ParentElementNumber)); queryBuildRange.value(’’);

} But am not sure how to write not equal to with the above code.

For example:

For the Purchase order of the project 100471 . the activity number displays with dropdown with the following values

  1. Petrofac Project (parentelementnumber == null)

  2. Northern island (parentelementnumber == 2)

  3. Southern Island (parentelementnumber == 3)

.

With the above list I want it to display in the look up as Northern Island and Southern Island where parentelementnumber is not null

Please let me know if am not clear.

Thanks

First of all, let me format your code so it becomes readable:

public void lookup(FormControl _formControl, str _filterStr)
{
    HierarchyTreeTable::lookupHierarchyTree(_formControl, ProjTable::find(purchLine.ProjId));
    Query query = new Query();
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildRange queryBuildRange;
    // SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(HierarchyTreeTable), this);
    HierarchyTreeTable::lookupHierarchyTree(_formControl, ProjTable::find(purchLine.ProjId));
    queryBuildDataSource = query.addDataSource(tableNum(HierarchyTreeTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldNum(HierarchyTreeTable,ParentElementNumber));
    queryBuildRange.value('');
}

First of all, this shouldn’t compile in AX 2012 and lower versions. Can you confirm your version and that the code is correct? (Please never forget to attach a tag with your AX version when creating new threads.)

Also, it doesn’t make sense. You create a query that’s it’s use anywhere. And you call HierarchyTreeTable::lookupHierarchyTree() twice with the same parameters, but you said you don’t want this logic even once.

If your goal is to modify the logic inside lookupHierarchyTree(), you can’t achieve it by creating a separate, unrelated query. You’ll have to modify the actual code called from lookupHierarchyTree() (or a copy of the code).

By the way, what if you use the third parameter of lookupHierarchyTree(), _showChildOnly? Won’t it give you what you need without any additional coding?

Thanks for your response. I am using AX2012 R2 . As you mentioned ,I need to change in lookupHierarchyTree method. From third parameter I am not able to fetch the ParentElementNumber field. Please let me how to fetch the ParentsElementNumber value for that particular project and check if it has null value or not. Sample code will b helpful since am new to this look up method.

The parameter is a Boolean value defining whether you want to fetch child records only or not. You set to true or false; trying to “fetch the ParentElementNumber field” from it doesn’t make any sense. Please try it. Only if you find that it doesn’t give you what you need, consider changing the lookup (HierarchyTreeLookup form and class).

Are you sure understand basics of AX development, such as how to use methods, method parameters, queries and so on? If not, you should learn basics first and move to more complicated things.

Thanks for your response. I fixed it by writing an alternate solution with Validate method where user should not select the activity number which has parentsElementnumber as null.

Have you at least tried _showChildOnly?

HierarchyTreeTable::lookupHierarchyTree(_formControl, ProjTable::find(purchLine.ProjId), **NoYes::Yes**);

It’s work for a few seconds.

Ya I have tried the above code but it doesn’t displays anything. Neither it did not show the lookup nor show the error also. On selection of lookup the screen was refreshing and did not display anything.