Wednesday, 29 June 2016

Working with maps

Use edit method to mark/unmark all records

In continuation to my previous post (Edit method - I), I'll now use edit methods to mark all and unmark all the records of a form. It is a very common requirement to have such ability on forms.
In this post we'll use the edit method created in previous post (Edit method - I) and continue to create new buttons on customer details form to mark all and unmark all records.

To achieve this,we'll be doing the following:
1. Create new buttons on customer details form to mark all and unmark all records.
2. Create new functions on customer details form to mark all and unmark all records.

Let's start:

1. Create 2 new buttons on the customer table form, and change their text property to "Mark All" and "Unmark All" respectively. The CustTable form design should look as shown below:

2. Now we create a new function on this form to mark all the records. Let's name this function as PAMarkAll. We traversed through all the records one by one using a while loop and called the edit method for each record to mark it. The code should look like:

In the above code, we have declared a variable of type custTable which will help us to traverse through all the records shown on the form.
Next we initialize it with the first record using
          custTable_ds.getFirst() function.
Then we start the while loop.
Please note the way we have called the edit method. The first parameter of the edit method signifies that the value is changed, the second parameter is the custTable variable which we are using to iterate the records on the form, the third parameter is to signify that value returned  from the edit method needs to be turned on.
After marking the currently selected record we will get the next record using
        custTable_ds.getNext() method.
The above loop will be executed till the next record is found.
At last we used element.redraw() method to redraw the form.

3. In the similar way we create a new function to unmark all the records, the only change is that we need to pass false as the third parameter in the edit method call. The function to unmark all the records should look as below:



4. The functions that we created above should be called when we click the mark all and unmark all buttons. To do this we override the clicked method of both the buttons. The clicked methods should look like:




Now that we are done with the modifications required to mark all/unmark all the records, let's open the customer master form and then play with mark all and unmark all buttons. On clicking mark all button we'll notice that all the records are marked.



On clicking Unmark all button we notice that all the records are unmarked.


So in the post we saw a good example where we can use edit methods in real time situations. In my coming posts, I'll show how we can use combination of edit and display method to achieve some good features to enhance user experience on Dynamics Ax forms.

Tuesday, 28 June 2016

Displaying an image on a form grid in Dynamics AX

Requiement to Get Warning Symbol   in form Grid :

In my case Warning : so changed the display method

Displaying an image on a form grid in Dynamics AX

Sometimes it is useful to display an image in  a data grid on a from to highlight certain records e.g. records with validation errors as in the example below:
















To achieve this requires 2 main steps:

1. Adding a display method on the table/form datasource that returns an ImageRes
 //BP Deviation Documented  
 display ImageRes errorExist()  
 {  
   #resAppl;  
   return this.ErrorLogged ? #ImageError : #ImageBlank2;  
 }  

2. Adding a new field control on the form by right-clicking on the Grid control within the form design and selecting New Control > Window




 

Set the properties of the new control as follows:





Wednesday, 22 June 2016

Reference lookup for Customer delivery address

I have a  requirement to get Customer Delivery Address in my form .

I have Customer field in my table and need to get all the delivery addresses for that customer as lookup to select for the new address field added.

Added a new field - Drag and drop ( sales line - delivery postal address field ).
maintain relation :  Table.DeliveryPostalAddr == LogisticsPostalAddress.Recid.
Add the field to form at required position. 
AutoDeclaration - yes to Reference Group. 
Properties :
data source - Inventlocation
ReferenceField : DeliveryPostalAddr
ReplacementFieldGroup - Location Reference.

Override Lookup reference method 
public Common lookupReference()
{
    CustTable                   custTable;
    DirPartyTable               dirPartyTable;
    DirPartyLocation            dirPartyLocation;
    LogisticsPostalAddress      logisticsPostalAddress;
    SysReferenceTableLookup     sysRefTableLookup;
    Query                       lookupQuery = new Query();
    QueryBuildDataSource        lookupQueryDataSource;

    // Construct the SysRefTableLookup object
    sysRefTableLookup = SysReferenceTableLookup::newParameters(tableNum(LogisticsPostalAddress),ReferenceGroup);

    // Add the field list that will be displayed on the lookup form
   // You can Change/Add more fields in lookup based on your requirement.

    sysRefTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Address));
    sysRefTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Location));

    // Construct the query's data source
    lookupQueryDataSource = lookupQuery.addDataSource(tableNum(LogisticsPostalAddress));

 // To add multiple values in range.
    while select  Location from LogisticsPostalAddress
        join DirPartyLocation
        join dirPartyTable
        join custTable
            where logisticsPostalAddress.Location == dirPartyLocation.Location
                && dirPartyLocation.Party == custTable.Party
                && custTable.Party == DirPartyTable.RecId
                && custTable.AccountNum == InventLocation.citCustAccount
    {
        // Add ranges to the query data source
        lookupQueryDataSource.addRange(fieldNum(LogisticsPostalAddress, Location)).value(queryValue(LogisticsPostalAddress.Location));
    }


    // Pass the query to the lookup object
    sysRefTableLookup.parmQuery(lookupQuery);

    return sysRefTableLookup.performFormLookup();
}


Before writing custom lookup first you have to add reference control in your form and you have to specify some properties as shown in the screen shot below,

http://dynamicsaxcloud.blogspot.in/2015/06/reference-lookup-for-customer-delivery.html




Wednesday, 8 June 2016

X++ passing current selected records in a form for your report

X++ passing current selected records in a form for your report

http://stackoverflow.com/questions/10014177/x-passing-current-selected-records-in-a-form-for-your-report


Pass the DS records to Class or pass the multiple records to class :

http://axhelper.blogspot.in/2012/01/pass-data-source-records-to-class-or.html

https://community.dynamics.com/ax/f/33/t/91411

http://stackoverflow.com/questions/10014177/x-passing-current-selected-records-in-a-form-for-your-report

http://stackoverflow.com/questions/10014177/x-passing-current-selected-records-in-a-form-for-your-report

https://community.dynamics.com/ax/f/33/p/91411/179700#.UT19BFeGPFk