Sunday, 5 March 2017

Multiselect LookUp Filter

1.Create a Form  and add three fields in design node (Cust_acc , SalesId ,Itemid with their respective EDT)
Important Note: Form without datasource (it is possible)
2.Declare the multiselect  buffer in class declaration

public class FormRun extends ObjectRun
{
SysLookupMultiSelectCtrl sysLookupMultiSelectCtrl;
}

3.Create init method in form method
public void init()
{
Query query = new Query();

QueryBuildDataSource qbds; //SysLookupMultiSelectCtrl msCtrlCust;

super();

qbds = query.addDataSource(tableNum(CustTable)); //qbds = query.addDataSource(tableNum(SalesLine));
qbds.fields().addField(fieldNum(CustTable,AccountNum));
sysLookupMultiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(element, Cust_Account, query);

}
4.create modified method in custaccount field in design node
public boolean modified()
{
boolean ret;
ret = super();
Sales_Id.lookup();
return ret;
}
5.Next in SalesId field create lookup method
public void lookup()

{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange qbr;
str txt;
    //
qbds = query.addDataSource(tableNum(SalesTable)); qbds.fields().addField(fieldNum(SalesTable, SalesId)); qbds.fields().addField(fieldNum(SalesTable, CustAccount));
 qbds.fields().dynamic(NoYes::No);
qbr = qbds.addRange(fieldNum(SalesTable, CustAccount));
 qbr.value(Cust_Account.valueStr());
txt = strReplace(Cust_Account.valueStr(),";",",");
 qbr.value(txt);
SysLookupMultiSelectCtrl::constructWithQuery(element, Sales_Id, query);

}

6.Create lookup method in ItemId field
public void lookup()
{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange qbr;

 str txt;
 qbds = query.addDataSource(tableNum(SalesLine));
 qbds.fields().addField(fieldNum(SalesLine, ItemId));
 qbds.fields().addField(fieldNum(SalesLine, SalesId));
 qbds.fields().dynamic(NoYes::No);
 qbr = qbds.addRange(fieldNum(SalesLine, SalesId));
 qbr.value(Sales_Id.valueStr());
 txt = strReplace(Sales_Id.valueStr(),";",",");
 qbr.value(txt);
 SysLookupMultiSelectCtrl::constructWithQuery(element, Item_Id, query);

}
7.Add modified method in same SalesId field
public boolean modified()
{
boolean ret;
ret = super();
Item_Id.lookup();
return ret;
}

 It will be filtered according to the custaccount next salesid and item id











Display Method in AX2012

  1. Create Two Tables  with fields (Customername, Itemname, Amount - Table1,Customername, Name ,Qty - Table2 ) 














2.After  that create a form with datasource
3.Add the fields in  design node.
4.Create  a new method in table you want to display(i.e Display  the  itemname in the name field of Table2)

Display ItemName Test()
{
    Display2 display2;
    Display1 display1;
    //ItemName name;
 select display2 where display2.CustomerName== this.CustomerName;
 return display2.ItemName;
}















5.Now go to Form -> Design Node-> Name field  properties  DATASOURCE  as Table2 & DATA METHOD  as Test() method name














6.Now you can see the output  i am getting the Item name in my Name field

Thursday, 2 March 2017

Argument Passing from ListPage to another form

  1. First Create Two tables  header and line  
  2. Create Two forms as header (ListPage) and line (Normal form) (listpage datasource  query must be created with two tables)
  3. In the header form and line form  add the respective datasource  i.e header and line table (in both the form)
  4. Create a menu item button in design node of Header Form  actionpane  and add a new method  in it(under the button ) 
  5. Link the menu item button with line table menuitem  (properties of menuitem button)
  1. Drag and drop the fields in the design node both the forms (grid  format) 
  2. Paste the code  below  in init method of line form 
public void init()
    {
          TestImport table1;
           super();
           table1 = element.args().record();
             TestImport_ds.query().dataSourceTable(Tablenum(TestImport)).addRange(fieldNum(table1,RecId)).
          value(SysQuery::value(table1.RecId));
        }
        • Open the header form and  click  the button you have created  after selecting the record in grid



        Important Note: screenshots based on my listpage   you can do it in  normal form also
         small difference is menu item button  in list page form  will be created
        in normal form  button is used





        final note: check the design field and button properties that are linked to the table

        Code for Import from Excel to AxTable


        1. First Create Two tables  header and line  
        2. Create Two forms as header and line 
        3. In the header form and line form  add the respective datasource  i.e header and line (in both the form)
        4. Create the xcel sheet  with you values according to the field in the table
        5. Create the job and paste the coding below  run it


        static void TestImport(Args _args)
        {

        SysExcelApplication application;
        SysExcelWorkbooks workbooks;
        SysExcelWorkbook workbook;
        SysExcelWorksheets worksheets;
        SysExcelWorksheet worksheet;
        SysExcelCells cells;

        int i;
        str com;
        COMVariantType type;
        FileName filename;
        TestImport header;
        TestImportline   line;
        int row;
        //int UnitQty;
        //int    VehicleNumber;
        //str AccountNumber;
        //str Name;
        //real Amount
        ;

        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        //specify the file path that you want to read
        filename = "G:\\Test.xlsx";
        try
        {
        workbooks.open(filename);
        }
        catch (Exception::Error)
        {
        throw error("File cannot be opened.");
        }

        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1); //Here 3 is the worksheet Number
        cells = worksheet.cells();
        do
        {
        row++;
        com = cells.item(row, 1).value().bStr();
        if(com!="0")
        {
        header.AccountNum=cells.item(row, 1).value().bStr();
        header.Name = cells.item(row, 2).value().bStr();
        header.Amount =(cells.item(row,3).value().double());
        header.insert();
            }
        if(conitem!="0")
            {
                line.AccountNum=  cells.item(row, 1).value().bStr();
                line.Amount= (cells.item(row,3).value().double());
                line.UnitQty= any2int(cells.item(row, 4).value().toString()); //(cells.item(row,4).value().int());
                line.VehicleNumber=any2int(cells.item(row, 5).value().toString());
                line.insert();
            }

        type = cells.item(row+1, 1).value().variantType();
        }
        while (type != COMVariantType::VT_EMPTY);
        application.quit();
        }

        Monday, 27 February 2017

        Report images change based on company name

        Using different images  according to selection of company

        here i am using  two images 

        you can see two images in the picture















        right click on the image and select   the image  properties and  click on the visibility tab 

        now click on the expression  box and enter the  expression 



        eg:=IIF(First(Fields!ItemId.Value, "student")="1101",False, True)

         after adding expression in one image now  repeat the same step  for another image 
        but the  condition differs ( you can see the condition in below pic)
















        Report generated is based on  my condition  parameter  itemid= 1003

        Sunday, 26 February 2017

        Reversing NumberSequence

        public void revSequenceByOne(ItemGroupId _groupId)
        {
        NumberSequenceTable     numberSeqTableRev,numberSeqLastRec;
        InventItemGroup         invItemGroup;
        str                     autonumber;
           
                  ttsBegin;
                  invItemGroup = InventItemGroup::find(_groupId);
           
                  if (invItemGroup && invItemGroup.NumberSequenceCode)
                  {
                      autonumber = invItemGroup.NumberSequenceCode;
                      numberSeqTableRev      = NumberSequenceTable::findByNaturalKey(autonumber);
           
                      select forUpdate firstOnly numberSeqLastRec
                          where numberSeqLastRec.RecId == numberSeqTableRev.RecId;
                      if (numberSeqLastRec.RecId && numberSeqLastRec.NextRec != 1)
                      {
                         numberSeqLastRec.NextRec -= 1;
                         numberSeqLastRec.update();
                      }
                  }
                  ttsCommit;
        }

        Validate for Another user not to use

        public void  validatewrite(Args _args)
        {
             boolean ret;
            NumberSequenceTable numberSequenceTable;
             LedgerJournalName  ledger;
            ledgerjournalname  tchk;
            LedgerJournalNameId  ledgerJournalNameId;
            select tchk where tchk.CheckBox== NoYes::Yes;
                if(tchk && tchk.JournalName!= ledger.JournalName)
                {
                     ledger.CheckBox= NoYes::No;
                     select tchk where tchk.CheckBox== NoYes::Yes;
                    ret = checkFailed("Already Journal Name: %1 is Checked",tchk.JournalName) );
                    // ret = checkFailed(strFmt("selected user",tchk.JournalName));
                   // throw error ("already selected by one user");

        }}

        AOT Query Filter by range through code

        static void Query_getRanges(Args _args)
        {
            Query                   query = new Query();
            QueryRun                queryRun;
            QueryBuildDataSource    qbd;
            CustTable               custTable;
            QueryBuildRange         range;
            int                     cnt, i;
            ;

            qbd = query.addDataSource(tablenum(CustTable));

            queryRun = new QueryRun(query);

            queryRun.prompt();   // To Prompt the dialog

            cnt = queryRun.query().dataSourceTable(tablenum(CustTable)).rangeCount();

            for (i=1 ; i<=cnt; i++)
            {
                range = queryRun.query().dataSourceTable(tablenum(CustTable)).range(i);
                info(strfmt("Range Field %1, Value %2",range.AOTname(),range.value()));
            }

            while (queryRun.next())
            {
                custTable = queryRun.get(tablenum(CustTable));
                info(strfmt("Customer %1, Name %2",custTable.AccountNum, custTable.Name()));
            }
        }

        How to restrict numbers in an String

        static void RestrictNumbersInString(Args _args)

        {
        #define.alphabets('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
        str     Field1;//is your field
        ;
        Field1 = "pravin022kumar";

        if((strkeep(substr(Field1,1,strlen(Field1)),#alphabets)!= substr(Field1,1, strlen(Field1))))
        {
            info(strfmt("%1","You cannot enter other than alphabets"));
            }
            else
            {
            info(strfmt("%1",Field1));
            }

        }

        Saturday, 25 February 2017

        Creating NumberSequence Table Level

        To Creating NumberSequence Table  Level
           

        1.  Create an edt : CarId .

             AOT >> Extended Data Types >> New  >> Properties >> Name  >> Car Id.

        2. Write a code on lode module() on NumberSeqModuleProject

        {
             datatype.parmDatatypeId(extendedTypeNum(Car Id));
             datatype.parmReferenceHelp(literalStr("@SYS334483"));
             datatype.parmWizardIsManual(NoYes::No);
             datatype.parmWizardIsChangeDownAllowed(NoYes::No);
             datatype.parmWizardIsChangeUpAllowed(NoYes::No);
             datatype.parmWizardHighest(999999);
             datatype.parmSortField(20);
             datatype.addParameterType(NumberSeqParameterType::DataArea, truefalse);
             this.create(datatype);
        }

        3.Write a method on Projparameters Table

             client server static NumberSequenceReference numRefcarId()
        {
             return NumberSeqReference::findReference(extendedTypeNum(car Id));
        }

        4.Write a job and run that

        static void Carid(Args _args)
        {
            NumberSeqModuleProject  NumberSeqModuleProject = new NumberSeqModuleProject();
            ;
            NumberSeqModuleProject.load();
        }


        5. Then run the wizard

           Organization Administration >> CommonForms >> Numbersequences>>Numbersequences>> Generate >> run the wizard.

        6.Now we have to check the number sequence  is correctly working  for that write a job:

        static void number(Args _args)
        {
            NumberSeq  numberSeq;
            CarId num;
            ;
            numberSeq = NumberSeq::newGetNum(ProjParameters::numRefcarId());
            num = numberSeq.num();
            info(num);
        }

          Run the above job.We will find the generated Numbersequence. 


        Now Create a new method in  the required table
         
        public void initValue()
        {
            NumberSeq       NumSeq;
            ;
            super();
            NumSeq =  NumberSeq::newGetNum(CustTable::numRefcarid(),true); //Your Table:: your method
            this.Car Id= NumSeq.num();  // your field name (EDT)

        }

        create a new method to get NumRefID

        public client server static NumberSequenceReference numRefcarid()
        {
            ;

            return NumberSeqReference::findReference(extendedTypeNum(carid)));
        }
         

        Running Values In Report

        If you want to check the running balance how does it work create a report 
        Eg:
        take Custtrans
        after finishing the steps in  Morphx environment  (dp class , contract class, menuitem)

        Add the fields in Visual studio  AccountNum  , Transdate , AmountCur
        again again the extra field to it and name it as  Running value 
         
         


        Add the expression in  Running value 


        After deploying in Visual Studio
        now you can see the result 

        Wednesday, 22 February 2017

        Amount in Words (Report)


        1. Declare a real variable in class  declaration    real  Amount;
        2. use this code at the end of insert Method //( Dp class)
          Amount  += inventjournaltrans.CostAmount; //(Mapping)
        3. and update Tmptable at the end of process report method.
           update_recordSet  TmpTable setting
            AmountInWords =Global::numeralsToTxt(Amount  );//Assigning the field to translate the text       format