Thursday 23 October 2014

Dynamic Selection in Form

Dynamic Selection in Form


1. On the Class Declaration of the form, add a query filter

    public class FormRun extends ObjectRun
   {
        QueryFilter queryFilterCustId;
    }

2. On the Data Sources ladder of the form, override the init method, note that it has the _ds extension

    public void init()
   {
        super();
        queryFilterCustId = WMPPickingLines_ds.query().addQueryFilter(WMPPickingLines_ds.queryBuildDataSource(),"CustAccount");

    }

3. Change the Control that will be used for the filter to have the property of AutoDeclaration set to Yes 

4. Override the modified method of the control to trigger the query

    public boolean modified()
   {
        boolean ret;
        WMPPickingLines_ds.executeQuery();
        return ret;
    }

5. On the Data Sources ladder of the form, override the executeQuery method, not that the controlName is required (in this case "CustomerId"). ValueStr is the method for getting a value from a drop-down.

public void executeQuery()
{

    QueryFilterCustId.value(element.design().controlName("CustomerId").valueStr());
    super();


Wednesday 22 October 2014

Unretrieved

Unretrieved Data

If the data shown on a table based datasource is showing as 'unretrieved' then follow these steps;

1.- Recompile and restore original table. Check fields with Table explorer; if table explorer doesn't show your field(s) properly, anything based on that table won't either. So, if this fails, go to step 3

2.- Recompile and restore form. Generate incremental CIL. Check it. If fail, go to step 3

3.- Restart Ax client and retry steps 1+2. If fail, go to 4

4.- Restart AOS. Retry steps 1+2.

Monday 20 October 2014

File Dialog


<URL> is the start folder


  FilePath  _selectedPath = @"<URL>";
  str _caption = "Test";
  boolean _showNewFolderButton;
  destinationFolder = WinAPI::browseForFolderDialog(_caption, _selectedPath, _showNewFolderButton);

Clearing Personalisation


Sometimes a personalisation of a screen can cause errors, the easiest way to clear any personalisation errors is to reset.


1.             In your Dynamics AX instance, you will want to navigate to ‘File’->Tools->’Options’
2.             Click on ‘Usage Data’ in the ‘Options’ form that opens up (top right menu)
3.             Click on the ‘Reset’ button in the ‘Usage Data’ form that opens up (bottom right)
4.             Click ‘Yes’. NOTE: This will only reset the usage data for your user, not anyone else’s

Monday 6 October 2014

Multiline grid selection


When something is clicked, work through the grid to get just the selected lines (ticked or highlighted)

void clicked()
{
    CustPaymModeTable custPaymModeTablelocal;
    MultiSelectionHelper helper = MultiSelectionHelper::construct(); // construct the helper class
    helper.parmDatasource(custPaymModeTable_ds); // set the datasource of the helper
    custPaymModeTablelocal = helper.getFirst(); //get the first selected record of the helper

    while (custPaymModeTablelocal.RecId != 0)
    {
        info(custPaymModeTablelocal.PaymMode);
        custPaymModeTablelocal = helper.getNext(); //get the next selected record of the helper
    }
}


Friday 3 October 2014

Current price of an item


public  PriceCur currentPrice(ItemId itemId, real qty, AccountNum accountNum )
{
    CustPriceGroup priceGroup;

    InventDim inventDim;
    InventTable inventTable;
    PriceDisc priceDisc;
    str unitId;
    Price price;
    ;
    itemId          = this.itemNumber;
    inventTable = InventTable::find(itemId);
    if(!inventTable)
    {
        return 0;
    }
    inventDim.initFromInventTable(inventTable);
    unitId = inventTable.salesUnitId();
    priceGroup   = CustTable::find(AccountNum).PriceGroup;
    priceDisc = new PriceDisc(ModuleInventPurchSales::Sales,ItemId,inventDim,unitId,today(),qty,accountNum);

    if (priceDisc.findPrice(priceGroup))
    {
        price = priceDisc.price();
    }
    else if (priceDisc.findItemPrice())
    {
        price = priceDisc.price();
    }

    return Price;
}

Or

priceDisc = new PriceDisc(ModuleInventPurchSales::Sales, itemId, InventDim::findOrCreateBlank(), prodBom.UnitId, systemdateget(), 1, custAccount, SalesTable.CurrencyCode);        

if (priceDisc.findPrice(custTable.PriceGroup))        
{        
    price = priceDisc.price();        
}        
else if (priceDisc.findItemPrice())        
{        
    price = priceDisc.price();        
}
        
salesPrice = priceDisc.price();



Thursday 2 October 2014

XSLT - Take out Microsoft's in SEPA



<?xml version="1.0" encoding="UTF-8"?>
<!-- Version 0.1, 27-09-2014 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sepa="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
  <xsl:template match="/">
    <xsl:copy-of select="//sepa:Document" />
  </xsl:template>
</xsl:stylesheet>

Ax2012 Parent/Child Linking In Grids


In the Data Sources of the Form, select the child table. In the data category of the child table, set the following;

  • JoinSource = <Parent table Name>
  • Link Type = delayed
  • Name = <Child table name>
  • Table = <Child table name>
Now as the data changes in the parent table grid, the data will change in the child grid.

NB : There has to be a relation set between the two data sources

Selective Data In Form Display



On the data sources section of the form ladder, under the data source, change the init method to select the data you require.

public void init()
{
    QueryBuildRange qryBuildRange;
    super();
    qryBuildRange = this.query().dataSourceName(this.name()).addRange(fieldNum(Addresses,AddressType));
    qryBuildRange.value(queryValue('D'));
    qryBuildRange = this.query().dataSourceName(this.name()).addRange(fieldNum(Addresses,dateCommited));
    qryBuildRange.value(queryValue(dateNull()));
    qryBuildRange.status(RangeStatus::Hidden);

}

The .Status being set to RangeStatus::Hidden stops the user over-ruling the selection manually.

Display Images In A Grid



  • Step 1 - Declare global variables in <yourform>.classdeclaration
public class FormRun extends ObjectRun
{
    Imagelist imageList;
    Image image;
}
  • Step 2 - Create Image List in <yourForm>.init
public void init()
{
    imageList = new ImageList(ImageList::smallIconWidth(), ImageList::smallIconHeight());
    image = new Image();
    image.loadResource(1030);  // tick icon
    imagelist.add(image);
    image.loadResource(927); // info icon
    imageList.add(image);
    image.loadResource(928); // warning icon
    imageList.add(image);
    image.loadResource(929); // red x icon
    imageList.add(image);

    super();
    
}

  • Step 3 - Create a window field on the grid
Set the AutoDeclaration of the window field to yes in the properties dialog
Load the image list to the window in <yourForm>.init after the super();

public void init()
{
    imageList = new ImageList(ImageList::smallIconWidth(), ImageList::smallIconHeight());
    image = new Image();
    image.loadResource(1030); 
    imagelist.add(image);
    image.loadResource(927);
    imageList.add(image);
    image.loadResource(928);
    imageList.add(image);
    image.loadResource(929);
    imageList.add(image);

    super();
    <windowField>.imageList(imageList);
}

  • Step 4 - Create method to set image on window field
On the table that is driving the grid, add a display method to set the picture in the window field.
The picture set is the data item in the array, not the icon number

public client server display int setIcon()
{
    #define.TickIcon(0)
    #define.InfoIcon(1)
    #define.WarningIcon(2)
    #define.StopIcon(3)

    
    if(!InventTable::find(this.itemNumber))
    {
        return #StopIcon;
    }
    else if(this.qtyOnHand() <= 0)
    {
        return #WarningIcon;
    }

    return #TickIcon;
}


  • Step 5 - Link window field to data
On the properties of the window field to point to the data method in step 4

DataSource  = <table in step 4>
DataMethod = <display method in step 4>