четверг, 7 июля 2016 г.

Lookup with possibility to choose color AX 2012

Hi to all!
Recently I've found kind of interesting piece of code, which allows us to choose color for row from Parameters form. You could use this parameter anywhere you want\need.
I just wanted to save this code for myself and then thought "It'd be unfair not to share it".
So, I'm going to share this code with you, hope it'd be helpful for you in your apps!

First of all, we need to create Int control on form with next properties
ColorSheme: RGB
Background color : black
Foreground color : black
Label foreground color (optional) : black
Choose datasourse and datafield if you want save this value in table

Override lookup method for this ds field\control and write next code:

public void lookup(FormControl _formControl, str _filterStr)
{
    Binary customColors;
    int             r, g, b;
    container       chosenColor;
    [r, g, b]   = WinApi::RGBint2Con(MCROrderParameters_CancelledLineColor.backgroundColor());
    chosenColor = WinApi::chooseColor(element.hWnd(), r, g, b, customColors, true);
    if (chosenColor)
    {
        [r, g, b] = chosenColor;
        MCROrderParameters.CancelledLineColor = Winapi::RGB2int(r, g, b);
        MCROrderParameters_CancelledLineColor.backgroundColor(MCROrderParameters.CancelledLineColor);
    }
}

Also, for better UI for user you could also override modified method and write next one:
public void modified()
{       MCROrderParameters_CancelledLineColor.backgroundColor(MCROrderParameters.CancelledLineColor);
} 
for change control color immediately.

That's all probably, hope it helps you sometimes!

пятница, 17 июня 2016 г.

What is the difference between Table.data() and buf2buf methods AX 2012


Hi all,
while creating a duplicate or copy of a record , generally we use table.data() method , for passing each  field one by one. The only problem with data() method is it would copy the system fields  also line ModifiedBy, CreatedBy etc, hence if we are inserting data across companies , we can't use data() method.

So what should be the solution for this?
Dynamics Ax also provides one more generic method buf2buf(_SourceRecord,_TargetRecord) , the only difference between Buf2Buf() and data() method is that buf2buf() doesn't copy system fields, which we need :-) 

So for intercompany data inserting, we should use buf2buf() method with changeCompany() method.

Looking forward to your comments.

среда, 9 декабря 2015 г.

How to hide ranges in query for dialog RunBase

I've got the same problem. 

And untull today I resolve this problem by adding 

qbr.addrange()  for index fields on table and after that make them dissapear throgh 

qbr.rangestatus(RangeStatus::Hidden).

But today I found new solution for hiding index fields as ranges in dialog.


All you need it override showIndexFields() method and depend on what ranges in datasource(table) you want to hide, you must return false for those ones.


Here's an example

public boolean showIndexFields(TableId id)
{
    boolean ret = true;
    switch (id)
    {
        case tableNum(DirPerson) :
            ret = false;
            break;
        case tableNum(HcmEmployment) :
            ret = false;
            break;
    }
    return ret;
}

If you'll have any questions, please , send an email, I'll be happy to answer on them!

пятница, 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!