Friday 17 August 2012

SysEmailBatch ?

SysEmailBatch mailer;
 
mailer = SysEMailBatch::construct();
mailer.parmPriority(emailPriority::Normal);
mailer.parmSenderAddr("Sender@mail.com");
mailer.parmSendername("Your name");
mailer.parmEmailAddr("receiver@mail.com");
mailer.parmEmailName("Receiver name");
mailer.parmSubject(subject);
mailer.parmMessageBody(msgBody);
 
mailer.run();

Thursday 16 August 2012

Mandatory DialogField

When adding controls to a standard form, either bound to a data field or not, one useful property is the Mandatory property. If this is set, then the control is shown with a red squiggly line if no value has been entered, and an error will automatically be shown when the user tries to save the record or close the form. This article describes how to also make this functionality available from dialog forms. You need to define the mandatory property in a DialogField class, as shown below.
1. Add mandatory() method into DialogField class:
// Created by GRR on 01.11.2005
void mandatory(boolean r)
{
    str name;
    // If properties exists then we are on server
    if (properties)
    {
        name = #Propertymandatory;
        if (! properties.exists(name))
            properties.add(name,true);
        properties.value(name,r);
    }
    else
        this.fieldControl().mandatory(r);
}
2. Add into unpack() method following lines:
case #PropertyMandatory:
    this.mandatory(unpackedProperties.valueIndex(i));
    break;


Determining if an object is a subclass

It can sometimes be useful to determine if an object is a instance of a subclass of some specified parent class.
While over-use of this probably suggests a class framework which has not been well designed, it is valuable in specific instances.
There are two static methods on the SysDictClass which can be used for this purpose:
static boolean isSuperclass(classId  _id, classId  _potentialAncestorId)
This method checks if the classId passed in _id is a subclass of the _potentialAncestorId
static boolean isEqualOrSuperclass(classId  _id, classId  _potentialAncestorId)
This method checks if the classId passed in _id is a subclass of the _potentialAncestorId, and will also return true if _id equals _potentialAncestorId
The following code uses the SalesTableType heirarchy as an example.
SalesTableType          stt;
SalesTableType_Journal  stt_j;
;
 
// This is true as stt is an ''instance'' of SalesTableType
if (SysDictClass::isEqualOrSuperclass(classidget(stt), classnum(SalesTableType)))
{
    // Code here will be run
}
 
// This is true as stt_j is a ''subclass'' of SalesTableType
if (SysDictClass::isEqualOrSuperclass(classidget(stt_j), classnum(SalesTableType)))
{
    // Code here will be run
}
 
// This is true as stt_j is an ''instance'' of SalesTableType_Journal
if (SysDictClass::isEqualOrSuperclass(classidget(stt_j), classnum(SalesTableType_Journal)))
{
    // Code here will be run
}
 
// This is FALSE as stt is NOT an instance or subclass of SalesTableType_Journal
if (SysDictClass::isEqualOrSuperclass(classidget(stt), classnum(SalesTableType_Journal)))
{
    // Code here will NOT be run
}

Monday 13 August 2012

Display Method explanation.

Introduction

A display method is not a physical field in a table but rather a method of displaying information from another table or source. It appears like a "normal" field and it can be used in forms and reports. For more information about display methods go to MSDN.

[edit] Usage

A display method can be created on either a table (in which case it is available for all forms using that table), or on the datasource of a specific form (in which case it is available only on that form).
Display methods must be created using a specific signature, which varies depending on the location of the method.

[edit] Display methods on tables

When declared on a table, display methods must be preceded with the keyword display and expect no parameters. The following example is a standard display method from the SalesTable table.
display CustName customerName()
{
    return this.partyTable_CustAccount().Name;
}

[edit] Display methods on datasources

When declared on a form datasource, display methods must have one non-optional parameter. The following example is from the PurchEditLines form in standard Ax 2012. The parameter is a buffer of the same type as that of the datasource on which the method is declared. It is essential as, when viewing a grid on a form, the method must know for which row the return value is to be calculated.
//BP Deviation documented
display ImageRes backOrder(PurchParmLine _purchParmLine)
{
    if (-InventTrans::backOrderQtyIssue(_purchParmLine.ItemId, _purchParmLine.InventDimId) > 0)
        return #Imageinfo;
 
    return 0;
}


[edit] Retrieving data from linked form datasources

When using a display method on a form datasource, it's possible to retrieve values from table fields in other datasources which are linked through an inner join to the current datasource. This is doing using the joinChild method and is illustrated in the example below.
This is the only reliable way to retrieve data from a joined datasource in a display method.
display public SalesQty remain(CustPackingSlipTrans _custPackingSlipTrans)
{
    if (isVersionArchived)
    {
        return _custPackingSlipTrans.joinChild().Remain;
    }
    else
    {
        return _custPackingSlipTrans.Remain;
    }
}


[edit] Limitations

A display method behaves like an ordinary field but has some limitations:
  • its data can not be changed (use edit method instead)
  • you can not filter and sort by display methods
If you need to sort and filter by a display method's data, there are the following workarounds
  1. Replace a display method with an ordinary stored field
  2. Replace a display method with inner joined table
The last is applicable if you have an often situation when display method simply returns a field value of the related table by mandatory field.
For example, you have a display method on the table named YourTable like the following:
//BP Deviation Documented
display EmplName emplName()
{
    return EmplTable::find(this.EmplID).Name;
}
If YourTable.emplID is mandatory, you can use an inner join instead of this display method:
  1. Place additional datasource on your form for EmplTable.
  2. Set LinkType property to 'InnerJoin'
  3. Add 'Name' field of the created EmplTable datasource to your Grid control or wherever else
If your original datasource is read only, your job is done. In the other case, when you try to add a new record to the datasource, you will see an error about mandatory fields of EmplTable. This error occurs because Ax tries to save joined datasource. To prevent such behaviour, you should
4. Override the write method of the EmplTable datasource with an empty implementation to prevent writing data to the table
public void write()
{
    // 'super' is commented out:
    // super();
}
5. Override the validateWrite method of this datasource to prevent error messages:
public boolean validateWrite()
{
    boolean ret;
    ;
    //ret = super();
    ret = true;
    return ret;
}
Now you can filter and sort your datasource by employee full name.

[edit] Caching

One significant side-effect of using display methods can be the impact on performance. Particularly when complex methods are used to calculate values being shown on grids, a visible slow-down in form performance can be experienced. This is largely due to the fact that the methods are often run repeatedly even when no reason is apparent and the values are unchanged.
To alleviate this, display methods on tables can be cached by using the cacheAddMethod method of the datasource object. To enable caching of a display method, call cacheAddMethod() from the init method of the datasource. This ensures that the display will only be calculated when necessary and can result in a significant performance improvement.
public void init()
{
    super();
 
    // Enable caching of the document handling display fields
    dirPartyTable_ds.cacheAddMethod(tablemethodstr(DirPartyTable, showDocHanIcon));
}
 
 
 
 
For more Information go with this link:http://www.axaptapedia.com/Display_method 

Thursday 9 August 2012

Showing the value of one field value on basis of another field on the dialog

The following code is for : When u select CustomerId in Field1 then it automatically takes the name of the selected CustomerId in field2...

public class ReportRun extends ObjectRun
{
     DialogField            dialogfield1,dialogfield2;
     CustAccount          custId;
     Name                   name;
}


 public Object dialog(Object _dialog)
  {
    DialogRunbase dialog = _dialog;
    ;
    dialog.caption('Customer information ');
    dialog.addGroup('Select CustomerId :');
    dialogfield1 = dialog.addField(typeid(CustAccount),"Cust Id : ");
    dialogfield1.value(custId);
    dialogfield2 = dialog.addField(typeid(Name),"Cust name : ");
    dialog.allowUpdateOnSelectCtrl(true);

    return dialog;
  }


public void dialogSelectCtrl()

{
     ;
     dialogfield2.value(custTable::find(dialogfield1.value()).Name);
}


boolean getFromDialog()
{
    ;
    custId   =   dialogfield1.value();
    name     =   dialogfield2value();
    return true;.
}

Display the data on the title bar?

Code to disply the emp_id on the title bar of the form

Path : MyEmplForm-->Data Sources-->MyEmplTable-->Methods-->active()


public int active()
{
    int  ret;
    ret  = super();
    element.design().caption(EmpLeaveDetails.Emp_Id);
    return  ret;
}


How to reverse a string in AX?

static void strReverve(Args _args)
{
str  s;
;
s =  'Test Info';
info(strReverse(s));
}

How to display date and time according to time zone ?

static void Job7(Args _args)
{
   ;
   //Current Date and Time according to time zone
   info(strFmt('%1',DateTimeUtil::newDateTime(systemdateget(),                                                                    timenow(),Timezone::GMT_CASABLANCA_MONTROVIA_REYKJAVIK)));

 //Todays Max Date and Time
info(strfmt("%1",DateTimeUtil::newDateTime(SystemDateGet(),Global::timeMax())));

}          

renaming a primary key. ?

I was given a task to perform renaming of Items in the InventTable.
In an environment that is to go live - so THERE WERE NO TRANSACTIONS OG STOCK LEVELS. If this has been the case we would have adviced the customer to live with it, as the renaming process potentially would have taken a very long time

Nearly 75% of the item numbers were named with 4 digits, the rest with 5.
The customer wanted only 5-digit item numbers.

How to do this in one go ?
A simple job is enough:


static void Job7(Args _args)
{

InventTable inventTable;
;

ttsbegin;
while select forupdate inventTable
where inventTable.ItemId LIKE "????"
{
inventTable.ItemId = "0"+InventTable.ItemId;
inventTable.renamePrimaryKey();
}
ttscommit;
}


or
Static void main updateIds(Args  args)
{
EmplTable  empltable;
Ttsbegin;
Select firstOnly forUpdate EmplTable where EmplTable.EmplId == ‘10001’;
If(emplTable.recId != 0)
{
emplTable.EmplId = ‘10101’(New EmplId);
EmplTable.renamePrimaryKey();
EmplTable.update()
}
Else
Info(‘employee not found’);
ttsCommit;
}


Wednesday 8 August 2012

How to convert the amount into words ?

display tempStr amountStr()
{
    if(netAmount <= 0)
    return   '-'+ ' ' + '(' + currCode + ') ' + numeralsToTxt(-(netAmount))+' '+'Only';
    else
    return   '(' + currCode + ') ' + numeralsToTxt_EN(netAmount)+' ' +'Only';
}

If a report attached to a form ,how can the report display the values of the selected one in form?

suppose i put my report on the  CustPackingSlipJour  form then i selected on e record,i want to display the information of that particular record only in my report then the following code helps    

public class ReportRun extends ObjectRun
{
    CustPackingSlipJour     externalCustPackingSlipJour;
}

public void init()
{
    element.initFromArgs(element.args());
    super();
}

void initFromArgs(Args args)
{
    if (args && args.dataset())
    {
        switch(args.dataset())
        {
               case tablenum(CustPackingSlipJour) :
                                        externalCustPackingSlipJour  =   args.record();        
        }
     } 
}

How to filter the data based on combo selection ?

DataDic-->Tables--->MedicineTable-->Fields

ItemId(string)
ItemExpired(enum)
ExpiryDate(date)

Medicine-->BaseEnums-->ItemExpired
ItemExpired :: Yes
                      No
                      All

MedicineInfoForm-->Methods-->classDeclaration

public class FormRun extends ObjectRun
{
    QueryBuildRange qbr;
}

 MedicineInfoForm -->DataSources--> MedicineTable -->Methods-->init()

public void init()
{
;
    super();
    qbr =    MedicineTable_ds.query().dataSourceTable(tablenum( MedicineTable )).addRange(fieldnum( MedicineTable ,ItemExpired));
    qbr.value(queryValue(ComboBox.selection()));
}

MedicineInfoForm-->Design--->Design-->Group : ItemExpired--->ComboBox:combobox-->Methods-->
modified()

public boolean modified()
{
    boolean ret;

    ret = super();

    if(combobox.selection()== ItemExpired::All)
    {
    qbr.value('');
    }
    else
    {
    qbr.value(queryValue(ComboBox.selection()));
    }

     MedicineTable_ds .executeQuery();

    return ret;
}

Explation on field fixed and related field fixed in table

Lets say you have ClothesTable and ClothesOrders.
ClothesTable has the following fields: ClotheId, Name and CollectionTypeId
MenClothesOrder has the following fields: OrderId, ClotheId, Qty  OrderId could be a number sequence and Qty entered manually bby the user.
CollectionTypeId has the following elements:
0 - Men
1 - Women
2 - Children
Example 1: Related Fixed Field
On MenClothesOrder we create a new relation to ClothesTable and specify the follwing two:
1. Normal = ClotheId to ClotheId (Best practice to specify this on the EDT) and
2. Related Fixed Field 0 = ClothesTable.CollecTionTypeId.
This shows that the lookup to the clothes table should show only clothes with the same ClotheId (point 1) AND clothes that are of type Men (point 2) because the our table deals with order for mens' clothes. We use 0 because Menis element 0 in the Enum.
Example 2: Fixed Field
This kinda works the other way round:
Imagine you have a ClothesOrders table (generic) and you have seperate tables for MenClothesTable, WomenClothesTable and ChildrenClothesTable. Fixed field says that the specified normal relation (on ClotheId) to MenClothesTable only works if the CollectionTypeId of the current record is set to 0 (Men) else the relation is disabled.

Learners blog

http://www.axaptapedia.com/Display_methodhttp://parimalajyothijp.blogspot.in/2012_01_01_archive.html
http://gotdax.blogspot.in/2009/12/batch-renaming-primary-key.html
http://dax-world.blogspot.com

















Tuesday 7 August 2012

displaymethod to get employee countryregionid

display AddressCountryRegionId SARdisplayEmployeeCountryRegion()
{
    DirPartyAddressRelationship         partyAddressRelationship;
    DirPartyAddressRelationshipMapping  addressRelationshipMapping;
    Address                             address;
    AddressCountryRegionId              ret;
    ;
    select  addressRelationshipMapping
    join partyAddressRelationship
    where partyAddressRelationship.PartyId == this.PartyId && partyAddressRelationship.IsPrimary &&
    partyAddressRelationship.RecId == addressRelationshipMapping.PartyAddressRelationshipRecId
    join address
    where address.RecId        == addressRelationshipMapping.AddressRecId &&
    address.DataAreaId   == addressRelationshipMapping.RefCompanyId;

    if(address)
    ret = address.CountryRegionId;
    else
    ret = '';
    return ret ;
}

A Fetch Method Override for A Date Range Data Retrival from Cust TRans Table as on ...

// #. A Fetch Method Override for A Date Range Data Retrival from Cust TRans Table as on ...
public boolean fetch()
{
    // 0. Declare Variables
    QueryRun qr;
    QueryBuildDatasource QueryBuildDatasource1;
    QueryBuildRange rangeTransDate;
    Boolean ret;
    CustTable custTable;
    CustTrans custTrans;

    // 1. A QueryRun object called qr is initialized with the active query of the report,
    qr = new QueryRun(element);

    // 2. Get DAtaSource from current element query
    QueryBuildDatasource1 = element.query().dataSourceTable(tablenum(CustTrans));

    // 3. A range for the customer transaction date field is added to Datasource
    rangeTransDate = QueryBuildDatasource1.addRange(fieldnum(CustTrans, transDate));

    // 4. Actusl Date Range Value is added to qr
    rangeTransDate.value(queryRange(systemdateGet() - daysBack, systemDateGet()));

    // 5. The range is locked, so the user cannot change it.
    rangeTransDate.status(RangeStatus::LOCKED);

    // 6. The transaction date range is added to the caption of the report.
    element.design().caption(strfmt("%1, %2", element.design().caption(), rangeTransDate.value()));

    // 7. At this point, the query is looped. The standard loop of the query and the printout of the
    // record is what the super() call in fetch() handles. Before the query is looped, there is a
    // check to see whether the dialogs for the query and the report are called.These are the two dialogs which are wrapped by RunBaseReportStd
    if (qr.prompt() && element.prompt())
    {
        // 8. query is looped
        while (qr.next())
        {
            // 9. Within each loop, the tables CustTable and CustTrans are initialized.
            // If no records are found, the loop breaks and the report ends.
            // If a data source has changed, a new record is found
            // and the record is printed using the send() method.
            custTable = qr.get(tableNum(CustTable));
            custTrans = qr.get(tableNum(CustTrans));

            if (!custTable)
            {
                ret = false;
                break;
            }
            // 10. Note the second parameter in the send() method.
            // The second parameter defines the level of the record. CustTable is on the first level of the query and
            // CustTrans is on the second level. This is important since, if it is not set correctly,
            // auto sums will not be printed.
            if (qr.changed(tableNum(custTable)))
            {
                 element.send(custTable, 1);
            }
            if (qr.changed(tableNum(custTrans)))
            {
                 element.send(custTrans, 2);
            }
        }
    ret = true;
    }
    else
        ret = false;
    return ret;
}
// 11.     ------Tactics of reports---
// In the fetch example, the query of the report was looped. The case could also be looping
// a WHILE statement, SELECT statement, or a combination of both. For each record
// looped in the query, you might want to select a record from a table which is not part of
// the query, or even build a temporary table to be printed. For each record to be printed,
// all you have to do is call the send() method
thnks

Monday 6 August 2012