Sunday, 31 May 2015

Creation of Default Dimension

static void CreateDefaultDimension(Args _args)
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;

    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;

    // Note that "Item" is not one of the default dimension,
    // but DimensionAttributeValueSetStorage will handle it gracefully
    container               conAttr = ["Department", "ExpensePurpose", "Item"];
    container               conValue = ["00000028", "Training", "1000"];
    str                     dimValue;

    for (i = 1; i <= conLen(conAttr); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }

        dimValue = conPeek(conValue,i);

        if (dimValue != "")
        {
            // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
            dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    result = valueSetStorage.save();
    info(strFmt("%1",result));
}

Sunday, 17 May 2015

Custom Lookup in Ax

public void lookup(FormControl _formControl, str _filterStr)
{
sysTableLookup sysTableLookup;
Query query = New Query();
QueryBuildDataSource qbdsJour, qbdsTrans,qdbsVend;
QueryBuildRange qbr;
;
sysTableLookup = SysTableLookup::newParameters(tableNum(VendPackingSlipJour), _formControl);
qbdsJour = query.addDataSource(tableNum(VendPackingSlipJour));
qbdsTrans = qbdsJour.addDataSource(tableNum(VendPackingSlipTrans));

qbdsJour.relations(true);
qbr = qbdsTrans.addRange(fieldNum(VendPackingSlipTrans, ItemId));
qbr.value(<ItemId>);
qbdsTrans.relations(true);
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, GRNNumber_IN));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, PurchId));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, OrderAccount));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();

}