0

I want to add a display method in the datasource of a listpage form. I can't add straightly because datasources come from an AOT query. How can I do it? Thanks for help in advance. The display method:

public display String255 UserNames()
{
    DirPartyName        partyName;
    DirPersonUser       personUser;
    DirPerson           person;
    UserInfo            userInfo;
    String255           userList = "";



    partyName = DirPersonUser::userId2Name(this.UserId);

    if(partyName)
    {
        while select Name from person
            exists join personUser
                where personUser.PersonParty == person.RecId
                    && personUser.User == this.UserId
        {
            userList += person.Name + ",";
        }
    }

    if (!partyName)
    {
        while select Name from userInfo 
            where userInfo.Id == this.UserId
        {
            userList += userInfo.name + ",";
        } 
    }
        partyName = (select firstonly Name from userInfo where userInfo.Id == this.UserId).Name;
    if (!partyName)
        userList += this.UserId + ",";

    strDel(userList,strLen(userList),1);
    return userList;
}
Rati Sharabidze
  • 69
  • 1
  • 12
  • You asked and answered this question yourself already in the [AX Community Development/Customization/SDK Forum](https://community.dynamics.com/ax/f/33/t/199943). Could you add the relevant information from there to your question and tell us what problems you have with your solution? – FH-Inway May 18 '16 at 13:53
  • It is another question. Now I need to make something like "item1,item2,item3.." for each item in a listpage form. so I need a display method defintely – Rati Sharabidze May 18 '16 at 15:18
  • From the other question you know that a table display method is the way to go. Did you try this and if yes, what problem did you encounter? Please note that currently your question is worded like a request for a tutorial, which is not a good fit for the Q&A format of Stack Overflow (take a look at [What topics can I ask about here?](http://stackoverflow.com/help/on-topic)). – FH-Inway May 18 '16 at 15:22
  • I do need a tutorial,I've read good books of AX(cookbooks,inside dynamics ax,MorphX IT,etc..) but nowhere is written such thing. The problem I encountered is that the result of the display method is just presented on the grid without being on the row of the right item,in other words it is not connected to the aot query. Anyway,if I had answered my question,why should I have asked it again ? :) – Rati Sharabidze May 18 '16 at 15:42
  • Could you explain the problem in more detail in the question itself and show the code of the display method and the properties of the form control? – FH-Inway May 18 '16 at 15:49
  • It is TrvExpenseReportsListPage and I want to add all approvers on each record,approvers quantity can be more than 1,that is why I have to seperate them with a comma(you can see that list in "View History"),so I need a display method.This is a standard AX form in Travel and Expneses>>Common>>All expense reports.I am not at work now,I will copy paste the code later. – Rati Sharabidze May 18 '16 at 16:04
  • Please edit your question instead of using comments and also post the properties of the form control of the display method. – FH-Inway May 19 '16 at 07:07
  • I modified this post,can you please tell me what shall I add to the code? – Rati Sharabidze May 19 '16 at 07:14
  • The properties of the form control that uses the display method. Also a description what the display method currently displays and what you expect it to display would be helpful. – FH-Inway May 19 '16 at 07:19
  • I am newbie in AX,I do not quite get what you mean in the form control properties. Do you mean the properties of the grid StringEdit? I simply drag&dropped it into the grid and set the datasource of the StringEdit on the table where is located this method. Is there something else to do? – Rati Sharabidze May 19 '16 at 07:52
  • Yes, I mean the properties of the `StringEdit` form control. What you describe sounds correct, but the properties are a common source of problems. Could you also tell us to which table you added the method and if the table is a data source in the list page query? – FH-Inway May 19 '16 at 08:05
  • Yes,the table is WorkflowWorkItemTable, I have put it in the datasource of the query,so it exists in the form. and the datasource property of the StringEdit is this table. I want that the aot query and this display method to be straightly connected – Rati Sharabidze May 19 '16 at 08:10
  • I will only repeat myself once: Could you please add all the information from your comments to the question itself, add a description what the display method currently displays and what you expect it to display and post the properties of the form control? Also does the display method return the correct results if you run it with a job? – FH-Inway May 19 '16 at 09:22

2 Answers2

0

Why don't you try writing display method in table method as use same in list page? That is good option. If you still want to write display method in form data-source level then change your display method like below.

public display String255 UserNames(DataSourcetablename _tableName) { ....

Use _tableName where ever you are using "this".

You can refer PurchEditLines form in standard Ax 2012 and see display ImageRes backOrder(PurchParmLine _purchParmLine).

For more details on display method click here

  • you can't simply add methods in datasources which come from an AOT query – Rati Sharabidze May 21 '16 at 16:04
  • To solve your issue "The problem I encountered is that the result of the display method is just presented on the grid without being on the row of the right item,in other words it is not connected to the aot query." is to pass the datasource parameter in display method. – Pradeep Muttikulangara Vasu May 22 '16 at 21:54
0

I had a same requirement and we did it with a real physical field in the table TrvExpTable after the field is in the table we fill it on opening the list page.

In the init(), before the super(), of the form you can call that method:

public void updateTrvExpTableApprovers()
{
    TrvExpTable             trvExpTable;
    TrvExpTrans             trvExpTrans;
    WorkflowWorkItemTable   workflowItemTable;
    String255               approversNames;
    HcmWorker               HcmWorker;
    DirPersonUser           dirPersonUser;
    Name                    name;

    ttsBegin;
    while select forUpdate trvExpTable where trvExpTable.ApprovalStatus == TrvAppStatus::Pending
    {
        approversNames = "";
        while select userId from workflowItemTable
            where workflowItemTable.RefRecId == trvExpTable.RecId &&
                  workflowItemTable.RefTableId == trvExpTable.TableId &&
                  workflowItemTable.Status == WorkflowWorkItemStatus::Pending
        {
            select firstonly hcmWorker
                join firstonly PersonParty, ValidFrom, ValidTo from dirPersonUser
                    where dirPersonUser.User == workflowItemTable.userId &&
                            hcmWorker.Person == dirPersonUser.PersonParty;
            name = HcmWorker.name();

            if (!name)
            {
                name = workflowItemTable.userId;
            }

            if(approversNames)
            {
                if (!strScan(approversNames, name, 0, 255))
                {
                    approversNames += ', ' + name;
                }
            }
            else
            {
                approversNames = name;
            }
        }

        trvExpTable.ApproversNames = approversNames;
        trvExpTable.update();
    }

    update_recordSet trvExpTable
        setting ApproversNames = ""
        where trvExpTable.ApprovalStatus != TrvAppStatus::Pending && trvExpTable.ApproversNames != "";

    ttsCommit;
}

It is not the most efficient way but in our case it is working perfect for more than a year now.

Also that way the user could CTRL+G on that field in the grid, which is not a option using the display methods.

Best Regards, Kristian

Kristian
  • 738
  • 6
  • 15
  • Thanks for your response, as I guess your idea is to create a new field in the table and give them a value with code. Thanks for your help, I will keep that in mind,I thought it to make with a display method (according to best practices),at the moment I realize taht sometimes I should ignore best practices :) – Rati Sharabidze May 19 '16 at 15:40