Thursday, October 22, 2009

Adding Array Field Range on QueryBuildDataSource

At some point in your miserable life, you will need to add a range to a QueryBuildDataSource to filter on an array field such as dimension.

 

Here is an example of a code to do it

 

public client static void lookupValidParentProj(FormStringControl ctrl)

{

    Query                query          =  new Query();

    QueryBuildDataSource queryBuildDataSource;

    ;

 

    queryBuildDataSource = query.addDataSource(tablenum(ProjTable));

     //this is how to add a normal range

    queryBuildDataSource.addRange(fieldnum(ProjTable, Template)).value(queryValue(NoYes::Yes));

    //this is how to add an a range on a particular array field. In this instance, the third field in the array

    queryBuildDataSource.addRange(FieldId2Ext(FieldNum(SalesLine, Dimension),3)).value(queryValue(SysQueryRangeUtil::currentEmplDepartment()));

 

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();

}

 

Thursday, October 15, 2009

Code Sample: Building a List type and displaying it

This is just a piece of code i want to remember so here it is. If you want to retrieve a list of data from somewhere and then display it, you can use this code. It also has example on how to use a container.

 

//this code can be on a table

static List getListOfWIPForCust(CustAccount   _custAccount)

{

    AxmWIPLookup    wipTotals;

    container       cont;

    List            list = new List(Types::Container);       //list will hold a container type

    ;

 

    if (_custAccount)

    {

        while select wipTotals

        where

               wipTotals.CustAccount == _custAccount

            && wipTotals.WIPTotal

        {

            cont = conins(cont,1,wipTotals.ProjId);                      //load the data in the container, column 1

            cont = conins(cont,2,wipTotals.WIPTotal);                //column 2

            list.addEnd(cont);                                                                //save it in the container

        }

    }

    return list;

}

 

//this code can be anywhere you want to call up that list

boolean closeClientValidated()

{

    AxmProjTableTotals  wipTotals;

    ProjId              projId;

    List                wipList;

    ListEnumerator      wipListIterator;

    container           cont;

    Amount              wipAmount;

    ;

 

    ret = true;

 

    if (CustTable.openBalanceMST())

        ret = false;

 

    //check WIP total

    wipList = AxmProjTableTotals::listOfProjWithWIP(CustTable.AccountNum); //load the list by calling the code above

    wipListIterator = wipList.getEnumerator(); //use this to traverse through the list

 

    if (!wipList.empty())

    {

        infolog.add(Exception::Info, "Projects with WIP for Customer " + CustTable.AccountNum);

        while (wipListIterator.moveNext()) //traverse through the list

        {

            cont = wipListIterator.current(); //load the current list dataset into a container

            projId = conpeek(cont,1);                //grab the first column data

            wipAmount = conpeek(cont,2);    //grab the second column data

            infolog.add(Exception::Info, "Project Code: " + projId + " WIP Total: " + num2str(wipAmount,10,2,1,2));

        }

    }

 

    return ret;

}

Wednesday, October 14, 2009

Finding out if a table's row has changed before updating

When putting code in the update method of a table, you want to find out whether the field you are updating has actually changed. This code can be found under the CustTable\update method.

 

It uses the recVersion to figure out if the record has changed.

 

void update(boolean _updateSmmBusRelTable = true, boolean _updateParty = true)

{

    CustTable this_Orig = this.orig();

    recVersion rv = this_Orig.RecVersion;

    ;

.

.

.

    if(this.RecVersion != rv && this_Orig.Name != this.Name)

    {

                //do your thang!

    }

.

.

.

 

}

Sunday, October 11, 2009

Not enough rights to use table 'Signature log' (SIGSignatureLog).


ERROR: “Not enough rights to use table 'Signature log' (SIGSignatureLog).”

SOLUTION: After installing AX5 SP1, it creates a new configuration key which it leaves unticked. go into Administration > Setup > System > Confiugration and tick the Electronic Signature tick box

Wednesday, October 7, 2009

Using value from methods for Filters



A neat (new?) AX functionality is to be able to use dynamic code to filter forms. For example, you can use a piece of code that returns a user’s current department and use it for your filter.




A few things must be done.


1. You can only use methods that are in SysQueryRangeUtil class (you can create your own in this class)


2. The method must be set to public static


3. When referencing the method in the filter screen, wrap it in parenthesis



A good example on how this is used is the query called smmContacts_MyContacts where the MainResponsible range value is ((Mainresponsible == currentEmployeeId()) && (Mainresponsible != ""))



Enjoy!