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