вторник, 5 мая 2015 г.

Multiselect Lookup form AX 2012

Hi everyone.
If you need to create lookup on form, but you can't use standard SysTableLookup class for create it, you can create your own lookup form for it.

In my case, I was needed to bring out 2 cloumns, which I took from View.
Also I need multiselect choise.

What you need to do:

Overrun init, run and closeOk methods on form:

init:
Spoiler:
super();
if(element.args() && element.args().caller() && element.args().dataset() == tableNum(ParentTable))
    {
        callerTable = element.args().record();
    }
run:
super();
this.setSelectedGroup();
closeOk:
Spoiler:
FormStringControl       callerFormControl       = SysTableLookup::getCallerControl(element.args());
    RefRecId                groupRefRecId;
    str                     selectedGroups;
    int                     lenOfStr;
    int                     i;
    container               courtesyCopyData;
    courtesyCopyData = element.getSelectedCopyGroups();
 
    //callerTable.CoutersyCopyGroupContainer = element.getSelectedCopyGroups();
    for (i = 1; i <= conLen(courtesyCopyData); i++)
    {
        groupRefRecId     = conPeek(courtesyCopyData, i);
        selectedGroups += Table::findByRecId(groupRefRecId).GroupId + #comma;
    }
    if(selectedGroups)
    {
        lenOfStr = strLen(selectedGroups);
        selectedGroups = strDel(selectedGroups, lenOfStr, 1);
    }
    callerTable.CoutersyCopyGroup = selectedGroups;
    if(callerFormControl)
    {
        callerFormControl.text(callerTable.CoutersyCopyGroup);
    }
    super(); 

Also, you need to create some methods for set selected records and insert them into table and get these selected records to your lookup:


Spoiler:
public container getSelectedCopyGroups()
{
    Table                               copyGroup;
    container                          selectedCopyGroups;
    int                                     i = 1;
    copyGroup = Table_ds.getNext(true);
    while (copyGroup)
    {
        selectedCopyGroups = conIns(selectedCopyGroups, i, copyGroup.RecId);
        i++;
        copyGroup = Table_ds.getNext();
    }
    return selectedCopyGroups;
}
public void setSelectedGroup()
{
    container   courtesyCopyData;
    int         i;
    RefRecId    RefRecId;
    courtesyCopyData = Table::findReferenceRecipientRecord(callerTable.RecId, CourtesyCopyType::CoutersyCopyGroup).CourtesyCopyData;
    if(conLen(courtesyCopyData))
    {
        for (i = 1; i <= conLen(courtesyCopyData); i++)
        {
            RefRecId = conPeek(courtesyCopyData, i);
            Table_ds.markRecord(Table::findByRecId(RefRecId), 1);
        }
    }
If you have any questions, I will be happy to answer them. 

Комментариев нет:

Отправить комментарий