dinsdag 31 augustus 2010

Retrieve label of EDT

How to get the label of an EDT?

See \Classes\DialogField\init
setting the label:
o.label(dictType.label(f));
with the dictType being:
dictType = new DictType(xtype);
and xtype being:
xtype = type >> 16;


Why do we have to right shift 16?
see \Classes\SysDictField\new
there you find a left shift 16
and global::fieldExt2Id does:
return (fieldExtId & 0xffff);

Also see http://www.eggheadcafe.com/software/aspnet/29515376/addfield-parameters.aspx
exerpt:
typeid() function gives you the id of a type. For eg:
you can try the following code in a job:
static void job1()
{;
print typeid(custAccount);
pause;
}
This will print out 6488075. In the AOT if you check up the ID of CustAcount
it is 99. But the above number that get from typeid function is a
combination of the ID in the AOT and the flag indicating that it is a user
type. The upper 16 bits contain the ID from the AOT (99)and the lower 16
bits contain the flag that it is a user type (11)
6488705 == (99 << 16 | 11)


Example:
public boolean validate(Object calledFrom)
{
    boolean ret;
    ToDate todate;
    dictType dictTypeLocal;
    ;


    ret = super(calledFrom);


    if (!toDate)
    {
        dictTypeLocal = new dictType(typeId(todate) >> 16);
        ret = checkfailed (strfmt("@SYS110217", dictTypeLocal.label()));


    }
    return ret;
}


Example - short version:
static void Job8(Args _args)
{
;
info(new dictType(typeId(ToDate) >> 16).label());
}



In Global Class:
public static LabelString aduTypeLabel(extendedTypeId _typeId)

{
;
return new dictType(_typeId >> 16).label();
}


Also (this example is a static method on ConfigTable):
static FieldLabel aduLabel()

{
;
return new SysDictType(extendedtypenum(ConfigId)).label();
}

modifiedField - previous value

Source: http://efreedom.com/Question/1-209764/Get-Previous-Field-Value-ModifiedField-Method-Dynamic-Ax-Table

Q: I would like to be able to perform some logic in the table.modifiedField method which compares the previous value of a field to the new value. How do I get to the previous value?

A: The record buffer as it was before any modifications is available through the this.orig() method.

Example:
public void modifiedField(fieldId _fieldId)

{
    super(_fieldId);
    info(strfmt("Field number %1 changed from %2 to %3",_fieldId,this.orig().(_fieldId),this.(_fieldId)));
}

donderdag 26 augustus 2010

How to create a production order with x++

Source: http://www.eggheadcafe.com/software/aspnet/31983659/how-to-create-a-production-order-with-x.aspx


static void CreateProductionOrder(Args _args)
{
ProdQtySched productionQty = 1;
ItemId productionItem = "AKU-1000";


ProdTable prodTable;
InventTable inventTable;
;
inventTable = InventTable::find(productionItem);


//Initialise the base values
prodTable.initValue();
prodTable.ItemId = inventTable.ItemId;
prodTable.initFromInventTable(inventTable);


prodTable.DlvDate = today();


prodTable.QtySched = productionQty;
prodTable.RemainInventPhysical = prodTable.QtySched;


//Set the active bom and route
prodTable.BOMId = BOMVersion::findActive(prodTable.ItemId,
prodTable.BOMDate,
prodTable.QtySched).BOMId;
prodTable.RouteId = RouteVersion::findActive(prodTable.ItemId,
prodTable.BOMDate,
prodTable.QtySched).RouteId;


prodTable.initRouteVersion();
prodTable.initBOMVersion();


//Use ProdTableType class to create the production order
prodTable.type().insert();
}

The code above set the active BOM / Route and also creates the InventTrans
data.

woensdag 25 augustus 2010

Form layout - Dropdown with descriptive field

How to properly layout a dropdown and an accompanying descriptive field.
Like this:




Example while creating an item:



This is how the AOT looks like:















































And this is how to set the properties on the group that contains the dropdown and its descriptive field:

vrijdag 20 augustus 2010

InventOnHand vs InventDimOnHand

See: http://www.dynamicsaxtraining.com/tips-tricks/inventonhand-vs-inventdimonhand

Axapta InventOnHand class is wrapper for InventSum table. Unique index for InventSum table is ItemId + InventDimId. In other word, this class is used to get on hand for item with specific dimension. For example, if you require getting on-hand qty for “Bottle” items that have “green” color, “standard” size and are stored in “22” warehouse, “1” Aisle, “4” Shelf then you use InventOnHand class.

But, if you require getting on-hand qty for warehouse location then InventOnHand class couldn’t help us. Because one location could contains different items. Or if you require get on-hand qty for pallet. In these cases InventDimOnHand class must be used. This class is used when you require on-hand qty for specific inventDim. InventDimOnHand сlass consists of InventDimOnHandMember classes. Each InventDimOnHandMember class contains information about Item, Dimensions and Qty

For example, see link.

donderdag 12 augustus 2010

Brief description of ways to close a form in AX

See http://kashperuk.blogspot.com/2010/07/tutorial-brief-description-of-ways-to.html

There are “only” 5 ways to close a form:
  • Close - close the form. Similar to the 'X' button.
  • CloseOK – close the form, and set the OK flag – called by the Commandbutton::Ok
  • CloseCancel – close the form, and set the Cancel flag – called by the Commandbutton::Cancel
  • CloseSelectRecord – close the lookup form, and set return record
  • CloseSelect – close the lookup form, and set return value
The below methods (note their names are in past-tense) are used to determine if or how a form was closed:
  • Closed – Returns true, if the form is no longer open
  • ClosedOK – Return true, if the form was closed by the user clicking ‘OK’
  • ClosedCancel – Returns true, if the form was closed by the user clicking ‘Cancel’
Finally, CanClose() is called before any of the close methods get called. If CanClose() returns false, the form is not allowed to close.

dinsdag 10 augustus 2010

Adding Find\Filter functionality on Display method

See http://matrishmangal.blogspot.com/2010/05/adding-findfilter-functionality-on.html

Inside SalesFormLetter class : ReArrange

See http://www.ksaelen.be/wordpress/2010/08/inside-salesformletter-class-rearrange/

num2str - decimals based on EDT

num2str function with the number of decimals based on the property of an Extended DataType

Code based on Mirko Bonello's work: http://dynamicsax-dev.blogspot.com/2009/02/getting-number-of-decimal-places-for.html


str num2strEdt(
    real _number,           //The real number to convert to a string
    int _character = 0,     //The minimum number of characters required in the text.
    ExtCodeValue _edt,      //The EDT to be used as basis for required number of decimal places.
    int _separator1 = 2,    //DecimalSeparator
    int _separator2 = 0)    //ThousandSeparator
{
    #DEFINE.AUTO('Auto')
    // http://www.rgagnon.com/pbdetails/pb-0181.html
    #DEFINE.LOCALE_USER_DEFAULT(1024)
    #DEFINE.LOCALE_ICURRDIGITS(25)

    #AOT
    #PROPERTIES
    #WinAPI // Used for regional settings

    TreeNode treeNode;
    int decimalPlaces;
    ;
    treeNode = infolog.findNode(#ExtendedDataTypesPath + '\\' + _edt);
    if (!treeNode)
        return strfmt("%1", _number);

    if (findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals) == #AUTO)
    {
      // get the number of decimals from the regional settings
      decimalPlaces = str2int((WinAPI::getLocaleInfo(#LOCALE_USER_DEFAULT,   #LOCALE_ICURRDIGITS)));
    }
    else
    {
      // get the number of decimals set by the developer in the property inspector
      decimalPlaces = str2int(findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals));
    }

    return num2str(_number, _character, decimalPlaces, _separator1, _separator2);
}

usage example:

info(strfmt("%1", num2strEdt(20.34, 0, (identifierstr(myEDT)))));

vrijdag 6 augustus 2010

Remember network passwords after reboot (Vista home premium)

Source: http://www.osnn.net/windows-desktop-systems/88876-vista-home-premium-remember-network-passwords-after-reboot.html


Hi, I was having the same issue as you, and I was using Vista Ultimate 64bits,

I got it to work by doing this:

1 - Reboot the computer
2 - After you log it will say your mapped drive couldn't be connected and stuff.... ok
3 - Go into Control Pannel, User Accounts, Network Passwords, and add the \\server\share, with the username & password you want
4 - Open My Computer, and access your mapped drive
5 - Reboot the computer

After this, all the time windows boots up it shall reconnect without that f*cking message again

Notice: Its important to do the steps as described because if you only add the server password into the Network Passwords but you don't use it, windows will not store it and will not remember the password the next time you boot.


Enjoy!!

donderdag 5 augustus 2010

Interactive Infolog messages: SysInfoAction

Ever wanted to doubleclick an infolog message and go straight to a form/field... ?

See:
http://www.axaptapedia.com/SysInfoAction_class
http://www.eggheadcafe.com/software/aspnet/35484927/sysinfoaction--open-form-with-parameters-from-infolog.aspx
http://alexvoy.blogspot.com/2008/04/sysinfoaction-and-infolog.html

Outputting the Name of an Enum element, instead of its Label

Example:

Enum WorkTimeControl has 3 elements:

Name - Label - EnumValue: (labels are in Dutch)
Open - Openen - 0
Closed - Afgesloten - 1
UseBasic - Basiskalender - 2


We define a variable:
WorkTimeControl workTimeControl = WorkTimeControl::Closed;

This code will render the Label of the element:
info(strfmt("%1", workTimeControl));
output = Afgesloten

This code will render the Name of the element:
info(strfmt("%1", enum2symbol(enumnum(WorkTimeControl), workTimeControl)));
output = Closed

WorkCalendarDate::findDate

A new useful method on Table WorkCalendarDate:

\Data Dictionary\Tables\WorkCalendarDate\Methods\findDate


/// <summary>
/// Searches the nth day of type _workTimeControl, forward or backwards from _startDate
/// </summary>
/// <param name="_calendarId">
/// The calendar to use to look for open days
/// </param>
/// <param name="_lookAheadDays">
/// Search for the nth day (default 0)
/// positive value = search forward
/// negative value = search backwards
/// </param>
/// <param name="_startDate">
/// Start looking from this date (default: system date)
/// </param>
/// <param name="_forceReturnDate">
/// What should be returned if no date was found?
/// true  = _startdate is returned
/// false = no date is returned (default)
/// </param>
/// <param name="_workTimeControl">
/// Look for which type of days?
/// Open (default)
/// Closed
/// UseBasic
/// </param>
/// <returns>
/// The nth day (_lookAheadDays) of type _workTimeControl, starting from _startDate
/// </returns>
/// <remarks>
/// location = \Data Dictionary\Tables\WorkCalendarDate\Methods\findDate
/// </remarks>
static TransDate findDate(
    CalendarId          _calendarId,
    Counter             _lookAheadDays   = 0,
    TransDate           _startDate          = systemDateGet(),
    boolean             _forceReturnDate    = false,
    WorkTimeControl     _workTimeControl    = WorkTimeControl::Open)
{
    WorkCalendarDate workCalendarDate;
    Counter          counter = 0;
    ;
    
    if (_lookAheadDays >= 0) //search forward from _startDate
    {
        while
        select workCalendarDate
            order by TransDate
        where workCalendarDate.CalendarId      == _calendarId
           && workCalendarDate.TransDate       >= _startDate
           && workCalendarDate.WorkTimeControl == _workTimeControl
        {
            if (counter >= _lookAheadDays)
                return workCalendarDate.TransDate;
            counter++;
        }
    }
    else                        //search backward from _startDate
    {
        while
        select workCalendarDate
            order by TransDate DESC
        where workCalendarDate.CalendarId      == _calendarId
           && workCalendarDate.TransDate       <= _startDate
           && workCalendarDate.WorkTimeControl == _workTimeControl
        {
            if (counter <= _lookAheadDays)
                return workCalendarDate.TransDate;
            counter--;
        }
    }

    //no date found
    if (_forceReturnDate)
        return _startDate;
    else
        return dateNull();
}


Example Job:

static void WorkCalendarDate_findDate(Args _args)
{
    CalendarId          calendarId;
    TransDate           startDate;
    TransDate           nextDate;
    Counter             offsetDays;
    Name                startDateName;
    Name                nextDateName;
    boolean             forceReturnDate;
    WorkTimeControl     workTimeControl;
    ;
    //Example 1:
    //Search 3 days forward in calendar STD, starting from 05 AUG 2010 (thursday), looking for Open days
    calendarId      = "STD";
    startDate       = str2date("05/08/2010",123);
    offsetDays      = 3;
    forceReturnDate = false;
    workTimeControl = WorkTimeControl::Open;
    
    nextDate        = WorkCalendarDate::findDate(
                        calendarId, 
                        offsetDays,
                        startDate, 
                        forceReturnDate, 
                        workTimeControl);
                        
    startDateName   = dayname(dayofwk(startDate));
    nextDateName    = dayname(dayofwk(nextDate));
    global::enum2int(
    info(strfmt("Search %1 days, starting from %2(%3), with an offset of %4 days = %5(%6)",
            workTimeControl,
            startDate,
            startDateName,
            offsetDays,
            nextDate,
            nextDateName)));
    //output:
    //Search Openen days, starting from 5/08/2010(thursday), with an offset of 3 days = 10/08/2010(tuesday)

    //Example 2:
    //Search 3 days backwards in calendar STD, starting from 11 AUG 2010 (wednesday), looking for Open days
    calendarId      = "STD";
    startDate       = str2date("11/08/2010",123);
    offsetDays      = -3;
    forceReturnDate = false;
    workTimeControl = WorkTimeControl::Open;
    
    nextDate        = WorkCalendarDate::findDate(
                        calendarId, 
                        offsetDays,
                        startDate, 
                        forceReturnDate, 
                        workTimeControl);
                        
    startDateName   = dayname(dayofwk(startDate));
    nextDateName    = dayname(dayofwk(nextDate));
    global::enum2int(
    info(strfmt("Search %1 days, starting from %2(%3), with an offset of %4 days = %5(%6)",
            workTimeControl,
            startDate,
            startDateName,
            offsetDays,
            nextDate,
            nextDateName)));
    //output:
    //Search Openen days, starting from 11/08/2010(wednesday), with an offset of -3 days = 6/08/2010(friday)
}