Thursday, 22 November 2012

Tasks


Task : INV11 - Modification to inventory transfer journal 

Invent Journal Trans : Init value ( datasource for the form – InventJournal Transfer
//CIT_INV11 - Modification to inventory transfer journal_BJU_22Oct2013<-
 
    passjournal = InventJournalTrans.JournalId;
    select * from inventjournalloc where inventjournalloc.journalid ==passjournal;
    if(inventjournalloc.FromInventLocationId && inventjournalloc.FromInventLocationId && inventjournalloc.FromInventLocationId && inventjournalloc.FromInventLocationId)
    {
        NewButton.visible(false);
        ItemList.visible(true);
        if(!InventJournalTrans)
        {
        Grid.enabled(false);
        }
    }
    else
        {
           NewButton.visible(true);
            Grid.enabled(true);
            ItemList.visible(false);
     }
 
Button Click – To pass Value…
//CIT_INV11 - Modification to inventory transfer journal_BJU_22Oct2013<-
void clicked()
{
    Args args;
    FormRun formRun;
    super();
    //info(strFmt("%1", passjournal));
 
    Args = new Args();
    Args.parm(passjournal);
    args.name(formStr(ItemList));
    formRun = classFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
     InventJournalTrans_ds.research();
    InventJournalTrans_ds.refresh();
}
//CIT_INV11 - Modification to inventory transfer journal_BJU_22Oct2013<-
 
// To retrieve value in Init () method of the form
public void init()
{
 
    super();
    //if(element.args().record() && element.args().record().TableId == tableNum(InventJournalTrans))
    //{
       // inventjournaltransloc = element.args().record();
 
        passjournal = element.args().parm();
 
    //}
 
}
 


Task 1 :  Create SSRS report  with  Sales Invoice
===============================================================================
To  Run DP class Through  Job
ICDOC_QMTmp iCDOC_QMTmp;

ICDOC_QMDP dataprovider =
new ICDOC_QMDP();
;

dataProvider.processReport();

iCDOC_QMTmp = dataProvider.getICDOC_QMTmp();


========================================================================================================================

Issues :

1.       To convert total invoice to text format :
while select sum(LineAmount)  from salesLineTmp where salesLineTmp.SalesId == _custInvoiceJour.SalesId
            {
                allPackIds = numeralsToTxt(salesLineTmp.LineAmount);
            }
2.       To get  selected  record  display when report open
Use  preRunModifyContract  method in Controller class.
   
3.       To display all the Packing slip of particular invoice separated by comma
Name allPackIds;
    #define.seperator(', ')
SalesLine  salesLineTmp;
while select PackingSlipId from custPackingSlipJour where CustPackingSlipJour.SalesId ==_custInvoiceJour.SalesId
    allPackIds += (custPackingSlipJour.PackingSlipId + #seperator);
    dNS_SOInvRepTmp.Packingslip = allPackIds;
4.       To display Image
5.        


Query



Temporary  Table :

Property –
Table type -  InMemory


DP

//Class Declaration
    SRSReportQueryAttribute(queryStr(DNS_SOInvRepQuery)),
    SRSReportParameterAttribute(classStr(DNS_SOInvRepContract))
]
class DNS_SOInvRepDP extends SRSReportDataProviderBase
{
    DNS_SOInvRepTmp  dNS_SOInvRepTmp;
    CompanyInfo                         companyInfo;
    Bitmap                              companyLogo;
     Bitmap                              emptyBitmap;
    CustPackingSlipJour custPackingSlipJour;
    SalesLine  salesLineTmp;
    Name allPackIds;
    #define.seperator(', ')
}
==================================================
 [SysEntryPointAttribute]
public void processReport()
{
    QueryRun queryRun;
    QueryBuildDataSource ds;
    QueryBuildRange range;
    Query query;
    CustInvoiceJour  custInvoiceJour;
    SalesTable salesTable;
    SalesLine salesLine;
    LogisticsPostalAddress  logisticsPostalAddress;
    DNS_SOInvRepContract contract;
    CustInvoiceId invoiceId;
    contract = this.parmDataContract() as DNS_SOInvRepContract;
    invoiceId = contract.parmInvoiceId();
    query = this.parmQuery();
     companyInfo                 = CompanyInfo::find();
     companyLogo = FormLetter::companyLogo();
  
 ds = query.dataSourceTable(tableNum(custInvoiceJour));
   
    queryRun = new QueryRun(query);
    while (queryRun.next())
    {
        custInvoiceJour = queryRun.get(tableNum(CustInvoiceJour)) as CustInvoiceJour;
        salesTable = queryRun.get(tableNum(SalesTable)) as SalesTable;
        salesLine = queryRun.get(tableNum(SalesLine)) as SalesLine;
        logisticsPostalAddress = queryRun.get(tableNum(LogisticsPostalAddress)) as LogisticsPostalAddress;
        this.insertDNS_SOInvRepTmp(
            custInvoiceJour,
            salesTable,
            salesLine,
            logisticsPostalAddress);
    }
}
 [
    SRSReportDataSetAttribute(tableStr(DNS_SOInvRepTmp))
]
public DNS_SOInvRepTmp getDNS_SOInvRepTmp()
{
    select dNS_SOInvRepTmp;
    return dNS_SOInvRepTmp;
}
=============================================
public void insertDNS_SOInvRepTmp(
    CustInvoiceJour _custInvoiceJour,
     SalesTable _salesTable,
    SalesLine _salesLine,
    LogisticsPostalAddress _logisticsPostalAddress)
{
   
    dNS_SOInvRepTmp.InvoiceId=_custInvoiceJour.InvoiceId;
    dNS_SOInvRepTmp.SalesId = _custInvoiceJour.SalesId;
    dNS_SOInvRepTmp.InvoicingName = _custInvoiceJour.InvoicingName;
    dNS_SOInvRepTmp.InvoiceDate  = _custInvoiceJour.InvoiceDate;
    dNS_SOInvRepTmp.Address = _logisticsPostalAddress.Address;
    dNS_SOInvRepTmp.CustomerRef = _salesTable.CustomerRef;
    dNS_SOInvRepTmp.ItemId = _salesLine.ItemId;
    dNS_SOInvRepTmp.SalesQty = _salesLine.SalesQty;
    dNS_SOInvRepTmp.SalesPrice  = _salesLine.SalesPrice;
    dNS_SOInvRepTmp.Name = _salesLine.Name;
    dNS_SOInvRepTmp.SalesUnit = _salesLine.SalesUnit;
    dNS_SOInvRepTmp.LinePercent = _salesLine.LinePercent;
    dNS_SOInvRepTmp.LineAmount = _salesLine.LineAmount;
    dNS_SOInvRepTmp.ComanyName =  companyInfo.name();
    dNS_SOInvRepTmp.CompanyAddress = companyInfo.postalAddress().Address;
    dNS_SOInvRepTmp.CompanyPhone = companyInfo.phone();
    dNS_SOInvRepTmp.CompanyLogo = companyLogo;
    //To get all Packing Slip Ids
    while select PackingSlipId from custPackingSlipJour where CustPackingSlipJour.SalesId ==_custInvoiceJour.SalesId
    allPackIds += (custPackingSlipJour.PackingSlipId + #seperator);
    dNS_SOInvRepTmp.Packingslip = allPackIds;
    // To get Total invoice amount in Words
        while select sum(LineAmount)  from salesLineTmp where salesLineTmp.SalesId == _custInvoiceJour.SalesId
            {
                allPackIds = numeralsToTxt(salesLineTmp.LineAmount);
            }
    dNS_SOInvRepTmp.TotalInvAmountInWords = allPackIds;
    dNS_SOInvRepTmp.insert();
    dNS_SOInvRepTmp.clear();
}


Contract

1.    [
2.       DataContractAttribute,
3.       SysOperationGroupAttribute('CustInvoiceId', "@LED10", '1')
4.   ]
5.   public class DNS_SOInvRepContract
6.   {
7.       CustInvoiceId invoiceId;
8.   }
9.    
10.    
 [
    DataMemberAttribute('invoiceId'),
    SysOperationGroupMemberAttribute('CustInvoiceId'),
    SysOperationDisplayOrderAttribute('1')
]
public CustInvoiceId parmInvoiceId(CustInvoiceId _invoiceId = invoiceId)
{
    invoiceId = _invoiceId;
    return invoiceId;
}

Controller

class DNS_SOInvRepController extends SrsReportRunController
{
    #define.ReportName('DNS_SOInvoiceReport.PrecisionDesign1')
    #define.ReportCaption('@LED12')
     CustInvoiceJour custInvoiceJour;
    DNS_SOInvRepContract dNS_SOInvRepContract;
}
==================================================
protected void preRunModifyContract()
{
    if (this.parmArgs()             &&
        this.parmArgs().record()    &&
        this.parmArgs().dataset() == tableNum(CustInvoiceJour))
    {
        custInvoiceJour = this.parmArgs().record();
    }
    if (!dNS_SOInvRepContract)
    {
        dNS_SOInvRepContract = this.parmReportContract().parmRdpContract();
    }
    dNS_SOInvRepContract.parmInvoiceId(custInvoiceJour.InvoiceId);
    super();
}
public void setRange(Args _args, Query _query)
{
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    if (_args && _args.dataset())
    {
        custInvoiceJour = _args.record();
    }
    qbds = _query.dataSourceTable(tableNum(CustInvoiceJour));
    qbr = qbds.findRange(fieldName2id(tableNum(CustInvoiceJour),fieldStr(CustInvoiceJour, InvoiceId)));
    if (!qbr)
    {
        qbr = qbds.addRange(fieldNum(CustInvoiceJour, InvoiceId));
    }
    if (custInvoiceJour)
    {
        qbr.value(custInvoiceJour.InvoiceId);
    }
}
//to Hide the TableIndex Fields on dialog
public boolean showQueryValues(str parameterName)
{
    return true;
}
public static void main(Args _args)
{
    DNS_SOInvRepController controller = new DNS_SOInvRepController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(false);
    controller.startOperation();
    if (controller.prompt())
    {
        controller.run();
    }
}


To enable  or disable  the  New and delete button and  some fields  related  to some table ie., customized :

Suppose  the field is  in  SMAServiceObjectRelation table,
Go  to Data source  "SMAServiceObjectRelation" of that form  , in that datasource  methods , write  in active method.
if(SMAServiceObjectRelation.StageAssetId)
    {
        smaServiceObjectRelation_ds.allowCreate(false); // Deny creating new object to that table
        smaServiceObjectRelation_ds.allowDelete(false);// Deny deleting existing object of the  table
        StageAssetDetails.visible(true); //// Make  total group along the fields underit visible
        Grid_StageAssetId.visible(true);// Make only  one field  as visible

 For this  we have  to see Autodeclaration  Property  of the fields  to Yes....

To  Get  look up based  on the value of other  field in that  form.

public void lookup(FormControl _formControl, str _filterStr)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    KR_CarType              kr_CarType;
    if(AssetGroup::find(AssetTable.AssetGroup).KR_IsCar == NoYes::No)
        super(_formControl, _filterStr);
    else
    {
        select kr_CarType where kr_CarType.Type == AssetTable.Model;
        sysTableLookup = SysTableLookup::newParameters(tablenum(KR_CarCategory), _formControl);
        sysTableLookup.addLookupfield(fieldnum(KR_CarCategory, Category), true);
        sysTableLookup.addLookupfield(fieldnum(KR_CarCategory, Description), false);
        queryBuildDataSource = query.addDataSource(tablenum(KR_CarCategory));
        queryBuildDataSource.addRange(fieldNum(KR_CarCategory,Category)).value(kr_CarType.MaintenanceInfo2);
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}


To  create  jump reference  to the field :
public void jumpRef()
{
    Args            args;
    MenuFunction    menuFunction;
    ;

    if(AssetGroup::find(AssetTable.AssetGroup).KR_IsCar == NoYes::No)
        super();

    else
    {
        args = new Args();
        menuFunction = new MenuFunction(menuitemdisplaystr(KR_CarCategory), MenuItemType::Display);
        args = new Args(menuFunction.object());
        args.caller(element);
        menuFunction.run(args);
    }
}

To  create  Lookup  to the field  ( if  table  contains multiple values with same ID) :

public void lookup(FormControl _formControl, str _filterStr)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    SysTableLookup          sysTableLookup;
     
        sysTableLookup = SysTableLookup::newParameters(tablenum(IPMInvestShareGroup), _formControl);
        sysTableLookup.addLookupfield(fieldnum(IPMInvestShareGroup,InvestShareGroupID ), true);
        sysTableLookup.addLookupfield(fieldnum(IPMInvestShareGroup,InvestorShareGroupName),true);
        queryBuildDataSource = query.addDataSource(tablenum(IPMInvestShareGroup));    
    //this  code  bring  distinct values  from table
        queryBuildDataSource.addOrderByField(fieldnum(IPMInvestShareGroup, InvestShareGroupID));
        queryBuildDataSource.addOrderByField(fieldnum(IPMInvestShareGroup, InvestorShareGroupName));
        queryBuildDataSource.orderMode(OrderMode::GroupBy);
    //this  code  bring  distinct values  from table
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();

 
}
To Get Lookup of fields  From Multiple tables in AX 2012 :
public void lookup()
  {
#define.seperator(', ')
      SysTableLookup tablelookup;
      QueryBuildRange qbr;
      QueryRun qrun;
      QueryBuildDataSource qbds1, qbds2;
      QueryBuildLink qblink1;
      Query q = new Query();
      IPMPFBanks  iPMPFBanks;
          Name allPackIds;
      ;
      tablelookup = SysTableLookup::newParameters(tableNum(BankAccountTable),this);
      qbds1 =  q.addDataSource(tableNum(BankAccountTable));
      qbds2= qbds1.addDataSource(tableNum(IPMPFBanks));
      qbds2.joinMode(JoinMode::InnerJoin);
      qblink1 = qbds2.addLink(fieldNum(IPMPFBanks,PortfolioAccount), fieldNum(BankAccountTable, AccountNum));
      qbds2.relations(true);
       while select iPMPFBanks where iPMPFBanks.PortfolioID ==IPMPFComodityTable.PortfolioID
      {
          allPackIds += (iPMPFBanks.AccountID + #seperator);
      }
      qbds1.addRange(fieldNum(BankAccountTable,AccountID)).value(allPackIds);//(queryValue(iPMPFBanks.PortfolioAccount));
      qbds1.addOrderByField(fieldnum(BankAccountTable,AccountNum ));
      qbds1.addOrderByField(fieldnum(BankAccountTable,AccountID ));
      qbds1.addOrderByField(fieldnum(BankAccountTable,Name ));
      qbds1.orderMode(OrderMode::GroupBy);
      tablelookup.parmQuery(q);
      //tablelookup.addLookupField(fieldNum(IPMPFBanks,PortfolioAccount));
     // tablelookup.addLookupfield(fieldNum(BankAccountTable,AccountNum));
      tablelookup.addLookupfield(fieldNum(BankAccountTable, AccountID),true);
      tablelookup.addLookupfield(fieldNum(BankAccountTable, Name));

      tablelookup.performFormLookup();
}
2nd Way :



SysTableLookup sysTableLookup;

QueryBuildDataSource qbds;

QueryBuildRange qbr;

sysTableLookup = SysTableLookup::newParameters(tableNum(IPMPFBanks), this);

qbds = query.addDataSource(tablenum(IPMPFBanks));

qbds.addDataSource(tableNum(BankAccountTable));

qbds.relations(true);

qbr = qbds.addRange(fieldNum(IPMPFBanks,PortfolioID));//.value(queryValue(IPMPfInvestmentLines.PortfolioID));

qbr.value(IPMPfInvestmentLines.PortfolioID);

sysTableLookup.parmQuery(query);

sysTableLookup.addLookupField(fieldNum(IPMPFBanks,PortfolioAccount));

//sysTableLookup.addLookupfield(fieldNum(BankAccountTable, AccountID));

sysTableLookup.addLookupfield(fieldNum(BankAccountTable, Name));

 

sysTableLookup.performFormLookup();*/
 
 
 
}

BankAccountTable - Master and IPMPFBanks uses the value AccountNum from it. Now  I need  lookup such that it maintains  range based on Account num. Getting Name, ID, from BankAccountTable and AccountNum from IPMPFBanks.
 
==============================================================
To Get Difference between Time zones  in AX 2012 :
 Job :
static void timezones(Args _args)
{
   //DateTimeUtil::applyTimeZoneOffset( hcmEmployment::findByWorker(_worker).ValidFrom, DateTimeUtil::getUserPreferredTimeZone());
    Timezone t,x;
    int64 a;
    int diff;   
    utcDateTime b, c, d;   
    t =  DateTimeUtil::getUserPreferredTimeZone(); // to get ax timezone
    x=Timezone::GMTPLUS0400YEREVAN;   
    b = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(), x);
    c = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(), t);   
    a = DateTimeUtil::getDifference(b,c);   
    diff = a/3600;// As  we get difference in Seconds . To get in hours.    
    info(strFmt("%1",a));
     info(strFmt("%1",b));
     info(strFmt("%1",c));
    info(strFmt("%1",diff));
}
=================================================================
lookups :


FormAutoLookupFactoryClass :

Introduced in AX 2012 which will help for form lookups on controls [strings, integers], Reference controls etc. by returning formRun class object

Example :
Create a new form with string Edit Field .
public void lookup()
{
    HcmWorker               selectedRecord;
    Args                    args;
    FormRun                 formRun;
    Form    workerLookupForm = new Form(formStr(HcmWorkerLookup));
    FormControl             control = this;
    FormStringControl       stringControl       = control as FormStringControl;
    args = new Args();
    args.name(formStr(HcmWorkerLookup));
    args.caller(this);
    args.parmObject(this);
    // position the lookup to highlight the current record
    // a string control supposed to contain a personnel number value
    selectedRecord = HcmWorker::findByPersonnelNumber(stringControl.text());  

if (selectedRecord.RecId != 0)
    {
        args.lookupRecord(selectedRecord);
    }
    // perform form lookup on the caller form control
    formRun = FormAutoLookupFactory::buildLookupFromCustomForm(stringControl, workerLookupForm , AbsoluteFieldBinding::construct(fieldStr(HcmWorker, PersonnelNumber), tableStr(HcmWorker)), args);
    stringControl.performFormLookup(formRun);
    //selectedRecord = formRun.selectRecordModeSelectedRecord();
}


Display Filtered data in  Reference Groups :

Code Snippet.


    Common                                ret;
    SysReferenceTableLookup   sysReferenceTableLookup;
    QueryBuildDataSource         queryBuildDataSource;
    Query                                   query = new Query();
    sysReferenceTableLookup =
    SysReferenceTableLookup::newParameters(tableNum(Department),_formReferenceControl, true);
    queryBuildDataSource = query.addDataSource(tableNum(Department));
    queryBuildDataSource.addRange(fieldNum(Department, Dept)).value(SysQuery::value(Dept::ComputerScience));

    sysReferenceTableLookup.addLookupfield(fieldNum(Department, Name));
    sysReferenceTableLookup.addLookupfield(fieldNum(Department, Dept));
    sysReferenceTableLookup.addLookupfield(fieldNum(Department, ID));
    sysReferenceTableLookup.parmQuery(query);

    ret = sysReferenceTableLookup.performFormLookup();
    return ret;





Look Up By Reference Fields :

Guys! In AX 2012, we could add the lookup in the form by reference field. For that It is necessary to understand the relations of tables. As we know relations between tables are used to associate rows in one table to rows in another table. In AX relationship between tables are defined within the MS Dynamics AX application and not at the physical database level. There are different sorts of relations. To get more detail visit the MSDN about How to Add a relation to a Table.
Lets say we have different categories of Items for storing in the inventory. I want to see specific category of items to be displayed in my lookup on inventory receiving form.
Start with adding relation in the inventory receiving table with items table. You can modify the relation according to your need. For showing the fruit category I have used related field fixed relation too

There must be field group defined in Items table.

Now add the reference group as  new control in the grid container of the form and set the DataSource, ReferenceField and ReplacementGroupField Properties.


can only see the fruits category in this look up


 

1 comment: