пятница, 29 мая 2015 г.

How to insert record in the end of the grid

Hello everyone!
I want to share with you some useful information.
I need to insert new records in the end of the grid. The DAX standatd behaviour's don't let this.
So I have found solution, how to do this.
Here's code, you just need to override create method on needed datasource:

public void create(boolean _append = true)
{
    this.last();
    super(_append);
}

The mose important in this code -  _append property.
By default it has false value, but we need to change it on "true"  otherwise our code won't work.

Please, if you have any questions - comment or send me e-mail!
Thanks!

четверг, 28 мая 2015 г.

How to show value in preview pane only for selected viewFilter

Hi, guys!
Today I want to show you, how you can set value for Preview Pane - Form Part special values or how you can get it visible and empty if you need this.
Here is code example for how make preview pane visible\hide:
void previewPaneVisible(boolean _show)
{
    FormRun         part;
    PartList        partList;
    ;
    partList = new PartList(Element);
    if (_show ^ (partList.partCount() > 0))
    {
       element.task(4478));
    }
}

And here's solution for  make preview pane empty on some cases:

void showPreviewRecords(boolean _show)
{
    int idx;
    Object part;
    PartList partList;
    partList = new PartList(element);
    for(idx = 1; idx<= partList.partCount(); idx++)
    {
        part = partList.getPartById(idx);
       if((part is FormRun) && (part.name() == identifieStr(yourListPageForm)))
       {
            part.ParmShowEmptyGrid(!_show);
       }
   }
}

If you have any questions  - please, comment or send me e-mail.

Thanks! 

вторник, 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. 

How to get string value with coma in View Dax 2012

Hello everyone!
Today I want to share with you some useful information.
I had a task:
get the value from table1 and bring them into one string with coma separator.
First I wanted to use display method, but display methods don't work in Views.
And I wrote the query for String Computed column, that returns the correct string value, which I needed.
Here's the code:

public static server str getLiveUserIdValue()
{
    str     curRecId = SysComputedColumn::returnField(tableStr(table), identifierStr(table), fieldStr(table, field));
    return '(select STUFF((select \',\'+ UserId from table where table.recid='+curRecId+' for xml path(\'\')), 1,1, \'\') as lst )';
}

This code hepled me to return correct value.
Hope, it'll be usefull for someone!