Search This Blog

May 30, 2012

How to find All Usr Layer Element in AOT

How to Find all the elements which in present in USR layer

To find all USR layer elements in AOT , you can write job with following code, when you will run this job it will create a new project named "TheAxapta_UsrObject". In this Project you find all elements which is present in USR layer by individual grouping. This a good way to find all USR element.

static void FilterBasedOnLayers(Args _args)
{

    sysprojectfilterrunbase upgradeproject;
    utilelements            theelements;
    ;

    upgradeproject = new sysprojectfilterrunbase();
    upgradeproject.parmProjectNode(systreenode::createProject('theaxapta_UsrObject'));
    upgradeproject.grouping(sysprojectgrouping::AOT);

    while select name, utilLevel, RecordType, ParentId from theelements

    where theelements.utilLevel == UtilEntryLevel::usr
    {
        try
        {
            theelements.reread();
            upgradeproject.doUtilElements(theelements);
        }

        catch (exception::Error)
        {
            throw error('error');
        }
    }

    upgradeproject.write();

    info('finish');
}

When this job is finished you get a new project in your Share Project node.
-Harry

May 29, 2012

How to convert a Amount in Words

How to Convert amount in words

Hi frnds this code will work for report as well as Forms also.  Of course this a lengthy code but you can write this in a class also  for reuse this code.

display Tempstr numberToRupees()
{
     int     numOfPennies = frac(TmpChequePrintout.AmountCur)*100 mod 100;
     int     test         = real2int(round(TmpChequePrintout.AmountCur,0));
     int     paise;
     int     numOfTenths;
     str 20  ones[19], tenths[9], hundreds, thousands, lakhs, crores, millions, billions;
     str 40  textpaise;
     int     tmpnumofpennies;
     int     temp;
     str 200 returntxt;

     int checkPower(int  _test, int _power)
     {
         int     numOfPower;

         if (_test >= _power)
         {
             numOfPower = _test DIV _power;
             if (numOfPower >= 100)
             {
                 temp = numOfPower DIV 100;
                 returntxt = returntxt + ' ' + ones[temp] + ' ' + hundreds;
                 numOfPower = numOfPower MOD 100;
             }
             if (numOfPower >= 20)
             {
                 temp = numOfPower DIV 10;
                 returntxt = returntxt + ' ' + tenths[temp];
                 numOfPower = numOfPower MOD 10;
             }
             if (numOfPower >= 1)
             {
                 returntxt = returntxt + ' ' + ones[numOfPower];
                 numOfPower = numOfPower MOD 10;
             }
             switch(_power)
             {
                 case 1000000000 :
                 {
                     returntxt = returntxt + ' ' + billions;
                     _test = _test MOD 1000000000;
                     break;
                 }
                 case 10000000 :
                 {
                     returntxt = returntxt + ' ' + crores;
                     _test = _test MOD 10000000;
                     break;
                 }
                case 100000 :
                 {
                     returntxt = returntxt + ' ' + lakhs;
                     _test = _test MOD 100000;
                     break;
                 }
                 case 1000 :
                 {
                     returntxt = returntxt + ' ' + thousands;
                     _test = _test MOD 1000;
                     break;
                 }
                 case 100 :
                 {
                     returntxt = returntxt + ' ' + hundreds;
                     _test = _test MOD 100;
                     break;
                 }
             }
         }
         return _test;
     }



     ones[1] = "@SYS26620";
     ones[2] = "@SYS26621";
     ones[3] = "@SYS26622";
     ones[4] = "@SYS26626";
     ones[5] = "@SYS26627";
     ones[6] = "@SYS26628";
     ones[7] = "@SYS26629";
     ones[8] = "@SYS26630";
     ones[9] = "@SYS26631";
     ones[10] = "@SYS26632";
     ones[11] = "@SYS26633";
     ones[12] = "@SYS26634";
     ones[13] = "@SYS26635";
     ones[14] = "@SYS26636";
     ones[15] = "@SYS26637";
     ones[16] = "@SYS26638";
     ones[17] = "@SYS26639";
     ones[18] = "@SYS26640";
     ones[19] = "@SYS26641";

     tenths[1] = 'Not used';
     tenths[2] = "@SYS26643";
     tenths[3] = "@SYS26644";
     tenths[4] = "@SYS26645";
     tenths[5] = "@SYS26646";
     tenths[6] = "@SYS26647";
     tenths[7] = "@SYS26648";
     tenths[8] = "@SYS26649";
     tenths[9] = "@SYS26650";

     hundreds    = "@SYS26651";
     thousands   = "@SYS26652";
     lakhs       = "Lakh";
     crores      = "Crore";
       millions    = "@SYS26653";
      billions    = "@SYS26654";


      test = checkPower(test, 1000000000);
     test = checkPower(test, 10000000);
     test = checkPower(test, 100000);
     test = checkPower(test, 1000);
     test = checkPower(test, 100);

     if (test >= 20)
     {
         numOfTenths = test DIV 10;
         returntxt = returntxt + ' ' + tenths[numofTenths];
         numOfTenths = numOfTenths MOD 10;
         test = test MOD 10;
     }
     if (test >= 1)
     {
         numOfTenths = test;
         returntxt = returntxt + ' ' + ones[numOfTenths];
     }
      if (numOfPennies)
     {
         returntxt = returntxt + ' ' + "@SYS5534" + "\n\n";
     }
     paise=numofPennies;
     if(paise)
     {
      if(paise >=20)
      {
       numofTenths= paise DIV 10;
       returntxt=returntxt + ' '+tenths[numofTenths];
       numofTenths = numofTenths MOD 10;
       paise=paise MOD 10;
      }
      if(paise >=1)
      {
       numOfTenths=paise;
       returntxt=returntxt+ ' '+ones[numOfTenths];
      }
      returntxt=returntxt+" Paise";
     }

    return   returntxt + "  Only";
    //return "(Amount in words)" +' ' + ' Rupees'+ " " +returntxt+" Only";
}

-Harry

May 28, 2012

Join Two Tables at Run Time

How to join Two tables at RunTime, without using Datasource


static void QueryJoin2Tables(Args _agrs)
{
AxTestTable1 AxTestTable1;  // Table 1
AxTestTable2 AxTestTable2;  // another table which you want to join with table 1
Query q;
QueryBuildDataSource qbdAxTestTable1, qbdAxTestTable2;  // objects for both tables
QueryBuildRange qbr;
QueryRun qr;
;

        q = new Query(); //to make a new query

qbdAxTeatTable2 = q.addDataSource(tablenum(AxTestTable2)); // To Add table to query

        qbdAxTesttable2.addRange(fieldnum(AxTestTable2,RollNo)).value("2");

         qbdAxTeatTable1 = qbdAxTestTable2.adddataSource(tablenum(AxTestTable));

       qbdAxTesttable1.addlink(fieldnum(AXTestTable2,RollNo),fieldnum(AxTestTable,Rollno));

       qbdAxTestTable.joinMode(joinMode::InnerJoin);
    qr = new QueryRun(q); // to fetch records from query
while(qr.next())
{
AxTestTable1 = qr.get(tablenum(AxTestTable));
info(AxtestTable.RollNo);
}
}

-Harry

May 25, 2012

Send Method


Hi frnd,

Overload your send method and copy paste following code, n yes dont forget to change the tables name here...



All d best ............:)


public boolean send(Common _cursor, int _level=1, boolean _triggerOffBody=TRUE, boolean_newPageBeforeBody=FALSE)
{
    boolean ret;
    LedgerJournalTrans ledgerJournalTrans1;

    if (_cursor.tableId == ledgerJournalTrans.tableId)
    {
        ledgerJournalTrans1 = _cursor;
    }
    if (ledgerJournalTrans.PaymMode == "RTGS" || ledgerJournalTrans.PaymMode == "NEFT")
    {
       ret = super(_cursor, _level, _triggerOffBody, _newPageBeforeBody);
    }
    return ret;
}

May 22, 2012

Merging Two records

Merging Two records


//we will explore how to correct such a situation by merging two records including
//all their related transactions. For the demonstration, we will merge two vendor accounts 5001
//and 5002 into a single one, that is, 5001.

static void VendAccountMerge(Args _args)
{
VendTable vendTable;
VendTable vendTableDelete;
PurchJournalAutoSummary jourSummary;
#define.vend('5001')
#define.vendDelete('5002')
;

     ttsbegin;
delete_from jourSummary
where jourSummary.VendAccount == #vendDelete;
select firstonly forupdate vendTableDelete
where vendTableDelete.AccountNum == #vendDelete;
select firstonly forupdate vendTable
where vendTable.AccountNum == #vend;
vendTableDelete.merge(vendTable);
vendTable.doUpdate();
vendTableDelete.doDelete();
     ttscommit;
}

May 08, 2012

Lookup in Table

Lookup in Table

Some times we need to create a lookuo on Tables itself, so to make a lookup in table methods add the following code in your object methods;

public static void lookupStaffTable(FormControl _callingControl, CITStaffPlanId _staffplan)
{
    Query query;
    QueryBuildDataSource qbds;
    SysTableLookup lookup;
    ;

    query = new Query();
    qbds = query.addDataSource(tablenum(CITStaffPlanLinesTable));
    qbds.addRange(fieldnum(CITStaffPlanLinesTable,StaffPLanId)).value(_staffplan);
    lookup = SysTableLookup::newParameters(tablenum(CITStaffPlanLinesTable),_callingControl,false);
    lookup.parmQuery(query);
    lookup.addLookupField(fieldnum(CITStaffPlanLinesTable, Position));
    lookup.addLookupField(fieldnum(CITStaffPlanLinesTable, ResourcesperPosition));
    lookup.addLookupField(fieldnum(CITStaffPlanLinesTable, TotalRequest));
    lookup.addLookupField(fieldnum(CITStaffPlanLinesTable, RecID),true);
    lookup.performFormLookup();
}

-Harry

May 04, 2012

Merging two Table Records

Merging two Table Records

Hi guys,
some times we need to merge two records within one line of table,
so to do this you can use following code, here for example i am using VendTabel and try to merge two vendors whose a/c no is 5001 and 5002 within 5001.

//we will explore how to correct such a situation by merging two records including
//all their related transactions. For the demonstration, we will merge two vendor accounts 5001
//and 5002 into a single one, that is, 5001.

static void VendAccountMerge(Args _args)
{
VendTable vendTable;
VendTable vendTableDelete;
PurchJournalAutoSummary jourSummary;
#define.vend('5001')
#define.vendDelete('5002')
;

     ttsbegin;
delete_from jourSummary
where jourSummary.VendAccount == #vendDelete;
select firstonly forupdate vendTableDelete
where vendTableDelete.AccountNum == #vendDelete;
select firstonly forupdate vendTable
where vendTable.AccountNum == #vend;
vendTableDelete.merge(vendTable);
vendTable.doUpdate();
vendTableDelete.doDelete();
     ttscommit;
}


Be Careful to use this job/Query coz it directly effect your data base

May 02, 2012

Enum values in Query ranges

Enum values in Query ranges

I've come accross a very geniun mistake which most of the developers usually do. Specially those who are working on a single language and do not test their code properly for other languages. This is related to the use of Enum values in Query ranges.

public void init()
{
QueryBuildRange criteriaOpen;
;
super();
criteriaOpen = this.query().dataSourceTable(tableNum(ProdTable)).addRange(fieldnum(ProdTable, ProdStatus));
criteriaOpen.value("Started");
// it does not work in non-English interface!!!
Though you will not find any compilation or run time error with this. However, the query will not read value when you run it in non english environment.
The correct way to use enum in query is
criteriaOpen.value(QueryValue(ProdStatus::StartedUp);
}



Did you got your answer.......??? :)