Contact Me

Total Pageviews

Monday 25 August 2014

ReportSection.executeSection() method and Programmable Section of a Report in Axapta

Prints the section in the report.It is the super() method call in the executeSection method that actually prints the section in the report.

As an Example,if you want a Page Break before printing a section in a report override the the ExecuteSection() method of the respective section and write:

public void executeSection()
{
    ;
    element.pagebreak();
    super();

}



We can use programmable sections to add any kind of customized information for example : sum of fields in the report .
To activate a programmable section, activate it explicitly with an element.execute(Number) statement. The Number must be specified in the ControlNumber property for the design section.
For example, I’ve created a programmable section calculating the sum of a column in dynamics ax .
To call this section , I add the method element.execute(1); in the fetch method after calling super() and before returning the result of the fetch
public boolean fetch()
{
;
    queryRun = new SysQueryRun(this.query());

    element.hideShowColumns();
    element.modifyQuery();

    while (queryRun.next())
    {

        projInvoiceJour = queryRun.get(tablenum(ProjInvoiceJour));

        gtInvoicedAmount       += projInvoiceJour.invoiceAmountMST();
        gtWIPInvoicedOnAcct    += projInvoiceJour.WIPInvoicedOnAcc();
        gtInvoicedRevenue      += projInvoiceJour.revenueMST();
        gtCostValue            += projInvoiceJour.CostValue;
        gtGrossMargin          += projInvoiceJour.contributionAmountMST();
    }

    super();

    element.execute(1); //Call the programmable Section 1 of the Report.
    return true;
}

The Programmable section contains 5 string controls with data method property set to 5 display methods each returning the Variables total calculated in fetch() method of the report like :

display AmountMST totalGrossMargin()
{
    return gtGrossMargin;
}   

Refer to the ProjInvoiceJournal report for the same. 

Happy Daxing :)

Sunday 24 August 2014

Morphx Report Development Basics

Today I am going to post some common Customizations required for Reports in Axapta:

1) How to change Report Caption at Runtime ?

Create a new  display method in the morphx report:

display Name ReportName()
{
  return element.design().caption("Caption Modified");
}

Set the Datamethod property of a string control as "ReportName".

2) How To display CompanyName in a Morphx Report ?

display Name companyName()
{
    return CompanyInfo::name();

}

3) Company Address in a Report ?

Display Addressing  companyAddress()
{
    ;
    return CompanyInfo::find().Address;

}

4)Display Total Number of Pages of a Report ?

display int PageTotal()
{
  return element.pagesTotal();

}

5) Page number of the Current Page in a Report 

display str 20 PageNum()
{
  return strfmt("%1",element.page());

}

6) Display CompanyLogo in a Report ?

display Bitmap companyLogo()
{
    return FormLetter::companyLogo();

}

Happy Daxing :-)

Saturday 23 August 2014

Changing Dynamics AX's forms' caption / text

Dynamics AX's forms' caption is composed of two parts: The name of the form / table being edited, and the primary key or at least two key fields that tell the user what record he has selected.

But do you know how to change these texts? I'll show you some ways of doing it in this post.

The first part of the caption, the name of the form, can be set on the Caption property, on the Design node of the form:



And that change can be seen on the left side of the form's caption:




Additionally, you can change the left part of the form through coding. Just add the following line on the init method or on whatever other key method you want it to be:

element.design().caption('Foo');

The second part, which is some information about the record, can be changed in two ways: through property settings, or through X++. I'll show both of them.

The table has two properties that you can use for this, the TitleField1 and TitleField2, under the Appearance node:




After setting them, you'll have to set another property on the form's Design node, the TitleDatasource, which should be the datasource related to your table:




And that's it, the value on the two fields you set on the TitleField1 and TitleField2 properties will be included on the form's caption:




And the last way to do it, through X++, is by overriding the caption method on the table. Of course that since we're changing something directly on the table, our change will reflect throughout the whole system. This means that if you change the caption of a table by overriding the caption method, you'll change the caption of all of the forms where that table was used as the form's caption.

We can do something simple, like this:

public str caption()
{
    str ret;

    ret = super();
    
    if (this.RecId)
    {
        ret = strFmt('Item number: %1, Total sold amount: %2', this.ItemId, this.getTotalSoldAmount());
    }

    return ret;
}

private real getTotalSoldAmount()
{
    return this.UnitPrice * this.SoldQuantity;
}


With the methods above defined on our example table, our form should look like this:




We only change the behavior if the record already exists on the database, by checking if it has a RecId set. We do that because we don't want to change the default text that appears on the form when the user is inserting a new record:






Friday 22 August 2014

Report Sections (MorphX Reporting Tools)

A Microsoft Dynamics AX report contains Methods, Data Sources, and Designs.     The Three major divisions that comprise of a AX Report are : Header, Body and Footer sections and each of which is further classified and has individual set of functionalities:
Prolog − The Prolog appears at the start of a report. It is printed before the page header on the first page of the report. Use it to display elements such as a logo, a report title, and current date.
Page Header − The Page Header appears at the top of every page in the report. Use it to display for example page number, date, and time.
Header − The Header appears at the start of a new group of records. Use it to display information such as group name.
Section Group − the Section Group appears in the middle of the report. A section group can contain a Header, Body, or a Footer section. Notice that the structure of the data sources is reflected in the structure of the section groups.
Footer − The Footer appears at the end of a group of records. Use it to display information such as sub totals.
Page Footer − The Page Footer section appears at the bottom of every page in a report. Use it to display information such as page numbers, if you did not insert them in the Page Header.
Epilog − The Epilog appears at the end of the report. Use it to display information such as disclaimers and general statements. The Epilog is printed just after the page footer on the last page in the report.
Programmable Section  The Programmable Section contains any kind of customized information.

Happy Daxing:)

Thursday 21 August 2014

Disabling some Form elements in Axapta

This X++ Code Snippet post will describe how you can disable a form element, based on the value of another form element.

As example, the CustTable form will be used. The example will disable the One-time customer checkbox on the General tab if the Mandatory credit limitcheckbox is checked on the same General tab.



  1. Select the Administration Field Group on the TabGeneral TabPage and set the AutoDataGroup Property to No.
  2. Select the Administration_OneTimeCustomer CheckBox field in the Field Group Administration and set the AutoDeclaration property to Yes.



Step 2: Create a form method to enable/disable the form element

Create a new form method setAccessOneTimeCustomer:

void setAccesssOneTimeCustomer()     
{ 

    if (CustTable.MandatoryCreditLimit)     
    { 

        Administration_OneTimeCustomer.enabled(false);     
    } 

    else     
    { 

        Administration_OneTimeCustomer.enabled(true);     
    } 

    custTable_DS.refresh();    
}



Step 3: call the form method in the active and the modified



Call the newly created form method in the active method on the Data Sourceof the Form. As such, the second field will be enabled or disabled appropriately upon scrolling through the form.


public int active() 

{   
    int ret; 
    element.setAccesssOneTimeCustomer(); 

    ret = super(); 

    return ret; 

}


Call the newly created form method in the modified method on the field which should trigger the enabling or disabling. In our example, it is the fieldMandatoryCreditLimit. As such the second field, in our case OneTimeCustomerwil be enabled or disabled each time the value of MandatoryCreditLimit is changed.


public void modified()   
{ 

    element.setAccesssOneTimeCustomer();     
    super(); 

}







Step 4: Test your modifications



Open the CustTable form: check the field Mandatory credit limit: the field One-time customer will be disabled immediately.


































Wednesday 20 August 2014

Work with Combo Boxes in a Form in Axapta

To work with a control in X++, the AutoDeclaration must be set to YES. In the control, choose properties and set AutoDeclaration to YES.














Find the methods for a ComboBox in the form (Form, Designs, Design, ... Group, ComboBox(name), Methods). Right click Methods, Override Method, choose "SelectionChange".





















public int selectionChange()
{
    int ret;

    ret = super();

    if(ComboBoxOnForm.selection() == SalesType::Journal)
    {
        Button.enabled(false);
    }
    else
    { 
        Button.enabled(true);
    }

    return ret;
}

HappyDaxing:)


Tuesday 19 August 2014

Call a Job from another Job in Axapta

1. Create simple job job_test  and add it to action menu item in AOT.
2. Call job_test in other job using following code.

   Args                    args; 
    ; 
    
    args = new Args(); 
    args.name(identifierStr(Jobs_Test)); 
    new menuFunction(menuItemActionStr(Jobs_Test), MenuItemType::Action).run(args);


If you want to add a job to a action menu item just create a new action menu item and set the object property of that menu item to point to the job created.

Monday 18 August 2014

Various methods of a Table in Axapta

ValidateField () fires every time the user changes the value in a field. The methods parameters give you the fieldId.

An Example of ValidateField() on a table in axapta is :

public boolean validateField(fieldId _fieldIdToCheck)
{
    boolean         ret;
    ;
    ret = super(_fieldIdToCheck);

    Switch (_fieldIdToCheck)
    {
          Case    fieldNum(MyTable,CustName) :
          
          if(strlen(this.CustName) < =3)
          ret = checkFailed("Customer Name must be longer than 3 characters"); 
          break;     

          Case   fieldNum(MyTable,PhoneNumber):
    
          ------//Validation Condition for this field//--------
          break;       
    }
    return ret;

}

ValidateWrite() Executed when a record is written to the database, before the data change is committed in the database(wen you save a record on a form).Used to check whether all mandatory fields are filled or not.


Example :

public boolean validateWrite()
{
    boolean ret;
    ;

    ret = super();

    if (!this.EstimatedArrivalDate)
    {
infolog.add(Exception::Warning,StrFmt("@SYS116347",fieldid2pname(tableNum(JSS_ProjBudgetTable),fieldNum(JSS_ProjBudgetTable,EstimatedArrivalDate))));
            ret = ret && false;
   }

    if (!this.EstimatedDepartureDate)
    {
infolog.add(Exception::Warning,StrFmt("@SYS116347",fieldid2pname(tableNum(JSS_ProjBudgetTable),fieldNum(JSS_ProjBudgetTable,EstimatedDepartureDate))));
            ret = ret && false;
    }

    if (this.EstimatedArrivalDate > this.EstimatedDepartureDate)
    {
            infolog.add(Exception::Warning,StrFmt("@SYS113171"));
            ret = ret && false;
    }
    return ret;

}

initValue() This method file while creating new record to initialize a value, here I am assigning user id to the userID field.

public void initValue()
{
super();
this.UserId = curuserid();
}

ValidateDelete() While deleting a record if we want to put any validation we can use this method. Here once I delete a record populating a info for that deleted record.

public boolean validateDelete()
{
boolean ret;
ret = super();
info(this.AccountNum);
return ret;
}

ModifiedField()

This method will execute if modified a record value, this works based on the field value.
Here I am using to fill the name field value according to the AccountNum

public void modifiedField(fieldId _fieldId)
{
CustTable ct;
;
super(_fieldId);
switch(_fieldId)
{
case fieldNum(Cust_new,AccountNum) :
{
this.Name = CustTable::find(this.AccountNum).Name;
}
break;
}
}

Happy Daxing :)





Sunday 17 August 2014

Created Date and Time Property of Table in Axapta

If you want to fetch the created date&time for a record inserted in table, firstly go to table property and enable 'createddate' & 'createdtime' property. thereafter extra field will be created in your table browser. now once you create record, can easily track the date and time from this field.

Saturday 16 August 2014

Difference between In Memory and Tempdb

     In Memory                                                               Tempdb

1. Holds data temporarily in client or                  1. Holds data temporarily in database
    server


2. These tables can't store in the database        2.These tables can store in the database.   
             .
3. Can't apply security.                                       3. Can apply security.         

Method Calling sequences of Table

When you press CTR+N
inItValue()->

When you change data in a field
validateField()  -> validateFieldValue() ->  ModifiedField() ->  ModifiedFieldValue()

When you close the table after entering some data
validateWrite() - > Insert()  -> aosValidateInsert()

When you open the table which will contain some data
If table will contain 10 records this method is called 10 times
aosValidateRead()

When you Save the Record for the first time

validateWrite() ->Insert() - > aosValidateInsert()
When you modify the record and saving

validateWrite() -> update() - > aosValidateUpdate()

When you delete the record
validateDelete() -> delete() -> aosValidateDelete()

Monday 11 August 2014

Lookup on Form Control Using Temporary Tables in Axapta

Create lookup using temporary table. Populate the temporary table with the required data in the init() method of the form.In the below example, the Tmpcontactperson table can populated with required data and the lookup called using the code below.

public void lookup()
{
    //insert record into temporary table in the init() method of the form
    sysTableLookup = SysTableLookup::newParameters(tableNum(Tmpcontactperson),this,false );
    sysTableLookup.addLookupField(fieldNum(Tmpcontactperson, ContactPersonId),True); sysTableLookup.addLookupField(fieldNum(Tmpcontactperson, CustAccount),false);
    sysTableLookup.addLookupField(fieldNum(Tmpcontactperson, Name),False);
    sysTableLookup.addLookupField(fieldNum(Tmpcontactperson, Email),False);
    sysTableLookup.addLookupField(fieldNum(Tmpcontactperson, Function),false);
    
sysTableLookup.parmTmpBuffer(tmpContactPerson); // Gets or sets the TmpBuffer
    sysTableLookup.performFormLookup();

}


In the classdeclaration method of the form declare the buffer of the Temporary Table

public class FormRun extends ObjectRun
{
  
    TmpContactPerson            tmpcontactperson;

}

Override the Init() method of the form and insert data into the Temporary Table.

   ContactPerson         contactperson;
    ;
    while select contactperson where contactperson.Name == "Robert Hernady"
    {
      tmpcontactperson.ContactPersonId = contactperson.ContactPersonId;
      tmpcontactperson.Name = contactperson.Name;
      tmpcontactperson.Email = contactperson.Email;
      tmpcontactperson.Function =contactperson.Function;
      tmpcontactperson.CustAccount = contactperson.CustAccount;
      tmpcontactperson.doInsert();

    }

Happy Daxing:)