Monday, 14 December 2015

how to use table buffer efficently

if(!suppItemGroup)
                        {
                            suppItemGroup.clear();
                            suppItemGroup.GroupId = inventTableModule.SuppItemGroupId;
                            suppItemGroup.Module =  ModuleInventCustVend::Invent;
                            suppItemGroup.insert();                          
                        }                      
                    select ItemId,ModuleType,SuppItemGroupId
                        from inventTableModuleloc
                            where inventTableModuleloc.ItemId         == inventTableModule.ItemId
                                &&    inventTableModuleloc.ModuleType == ModuleInventPurchSales::Sales;                      
                                inventTableModuleloc.clear();
                                inventTableModuleloc.SuppItemGroupId = inventTableModule.SuppItemGroupId;                              
                                inventTableModuleloc.ModuleType      = ModuleInventPurchSales::Sales;
                                inventTableModuleloc.insert();
                                                   
                    select ItemId,ModuleType,SuppItemGroupId
                        from inventTableModuleloc
                            where inventTableModuleloc.ItemId == inventTableModule.ItemId
                                &&    inventTableModuleloc.ModuleType == ModuleInventPurchSales::Purch;                              
                                inventTableModuleloc.clear();
                                inventTableModuleloc.SuppItemGroupId = inventTableModule.SuppItemGroupId;
                                inventTableModuleloc.ModuleType      = ModuleInventPurchSales::Purch;
                                inventTableModuleloc.insert();  


if we see the above code we are using a single table buffer which we are clearing and re inserting it is better than creating a new buffer and using it.


display methods

normally we do caching of display method for the performance issue

best thing we can do is 

we can simple write on every display method top 

as 

[SysClientCacheDataMethodAttribute(true)]

that's it rest of things will be taken care..

no need to add cache method in form data source and normally try to write the display emthods on the tables rather than writing on the form level.

Thursday, 10 December 2015

code to get the child node in product hierchery

static void queryForHierarchyNodes(Args _args)
{
    EcoResCategory          ecoResCategoryMobile, ecoResCategoryInfo, ecoResCategoryLast;
    QueryRun                qRun;
    QueryBuildDataSource    qDS;
    #EcoResCategoryDefaults

    select * from ecoResCategoryMobile where ecoResCategoryMobile.RecId == 5637170077 ;//5637163389;//5637163386; //5637163389;

    qRun        = new QueryRun(new Query());
    qDS = qRun.query().addDataSource(tableNum(ecoResCategory));

    qDS.addRange(fieldNum(EcoResCategory, CategoryHierarchy))
                    .value(queryValue(ecoResCategoryMobile.CategoryHierarchy));

    qDS.addRange(fieldNum(EcoResCategory, NestedSetLeft))
                    .value(Global::queryRange(ecoResCategoryMobile.NestedSetLeft, ecoResCategoryMobile.NestedSetRight));

    qDS.addRange(fieldNum(EcoResCategory, NestedSetRight))
                    .value(Global::queryRange(ecoResCategoryMobile.NestedSetLeft, ecoResCategoryMobile.NestedSetRight));

    while (qRun.next())
    {
        ecoResCategoryInfo  = qRun.get(tableNum(EcoResCategory));
        //select ecoResCategoryLast where ecoResCategoryLast.ParentCategory == ecoResCategoryInfo.RecId;
        //if(!ecoResCategoryLast)
        {
            //info(ecoResCategoryInfo.getLeafNodes().Name);
            info(ecoResCategoryInfo.Name);
        }
    }
}

Wednesday, 9 December 2015

how to form a query based on relation

static void newjob(Args _args)
{
    EcoResDistinctProductVariant        EcoResDistinctProductVariant;
    EcoResProductVariantConfiguration   EcoResProductVariantConfiguration;
    EcoResProductMaster                 resproductmaster;
    EcoResConfiguration                 EcoResConfiguration;
    Query                   query = new Query();
    QueryRun                qr;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildDataSource    queryBuildDataSource2;
    QueryBuildDataSource    queryBuildDataSource3;
    QueryBuildDataSource    queryBuildDataSource4;
    QueryBuildRange         queryBuildRange;
    QueryBuildRange         queryBuildRange2;
    SysTableLookup          sysTableLookup;
    EcoResConfiguration     EcoResConfiguration1;
 
   
    select * from resproductmaster  where resproductmaster.DisplayProductNumber == "SamsungS20";  
   
    while select * from EcoResDistinctProductVariant  where EcoResDistinctProductVariant.ProductMaster == resproductmaster.RecId
    {      
        select * from EcoResProductVariantConfiguration  where EcoResProductVariantConfiguration.DistinctProductVariant == EcoResDistinctProductVariant.RecId;
        select * from EcoResConfiguration  where EcoResConfiguration.RecId == EcoResProductVariantConfiguration.Configuration;
        info(strFmt("%1",EcoResConfiguration.Name));
    }
   
   
    queryBuildDataSource    = query.addDataSource(tableNum(EcoResConfiguration));
    queryBuildDataSource2   = queryBuildDataSource.addDataSource(tableNum(EcoResProductVariantConfiguration));
    queryBuildDataSource2.addLink(fieldNum(EcoResConfiguration, RecId), fieldNum(EcoResProductVariantConfiguration, Configuration));
    queryBuildDataSource3   = queryBuildDataSource2.addDataSource(tableNum(EcoResDistinctProductVariant));
    queryBuildDataSource3.addLink(fieldNum(EcoResProductVariantConfiguration, DistinctProductVariant), fieldNum(EcoResDistinctProductVariant, RecId));
    queryBuildDataSource4   = queryBuildDataSource3.addDataSource(tableNum(EcoResProductMaster));
    queryBuildDataSource4.addLink(fieldNum(EcoResDistinctProductVariant, ProductMaster), fieldNum(EcoResProductMaster, RecId));
    queryBuildDataSource4.addRange(fieldNum(EcoResProductMaster, DisplayProductNumber)).value("Galaxy S Duos Gold");

    qr = new QueryRun(query);
    while(qr.next())
    {
        EcoResConfiguration1 = qr.getNo(1);
        info(EcoResConfiguration1.Name);
    }
   
}

a query with multiple datasource

public void lookup(FormControl _formControl, str _filterStr)
{
    Query                       query = new Query();
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsJoin;
    SysTableLookup              sysTableLookup;
    CompanyInfo                 CompanyInfo;
   // super(_formControl, _filterStr);
    changeCompany(DMS_IMEIDelinkingTable.DataArea)
    {
        select firstOnly DMSDivisionCode
            from CompanyInfo
                where CompanyInfo.DataArea == DMS_IMEIDelinkingTable.DataArea;
        sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), _formControl);

        qbds = query.addDataSource(tableNum(InventTable));
        qbdsJoin = qbds.addDataSource(tableNum(DmsSkuDetailsTable));
        qbds.relations(false);
        qbds.fields().dynamic(NoYes::Yes);
        qbdsJoin.addLink( fieldNum(InventTable, ItemId),fieldNum(DmsSkuDetailsTable, ProductCode));
        qbdsJoin.joinMode(JoinMode::InnerJoin);
        qbdsJoin.addRange(fieldNum(DmsSkuDetailsTable,DivisionCode)).value(CompanyInfo.DMSDivisionCode);
        qbdsJoin.addOrderByField(fieldnum(DmsSkuDetailsTable, ProductCode));
        sysTableLookup.addLookupField(fieldnum(InventTable, ItemId));
        sysTableLookup.addLookupField(fieldnum(InventTable, NameAlias));
        qbds.orderMode(OrderMode::GroupBy);
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}

Monday, 7 December 2015

BP error : dateflag should be specified when calling date2str

code  :

  return date2str(_cv.date(),123,2,1,2,1,4);

it wil give bp error :

"date flags should be specified when calling date2str"

Change it too below :

return date2str(_cv.date(),123,2,1,2,1,4,DateFlags::None);





Thursday, 3 December 2015

enable or disable field based on condition ax 2012

there are 2 ways to enable or disable the fields :

1.

inventTable_ds.object(fieldnum(InventTable,ItemId)).enable(True);

2. itemid.enable(true)

always prefer first one as this is considered as best practises
and you don't need set the auto declaration == yes also.


Wednesday, 2 December 2015

Exception -The ' ' character, hexadecimal value 0x20, cannot be included in a name

private void XMLChilddata(DmsTableFieldMapping _mapping,common _recordChild)
{
    str                     strValue;
    XmlAttribute            labelAttribute;
    //InventJournalTable      InventJournalTableloc;
    InventJournalTrans      InventJournalTrans;
    //SysDictField            dict;

    if(_recordChild.TableId == InventJournalTable.TableId)
    {
        while select ItemID
            from InventJournalTrans
                where InventJournalTrans.JournalId == InventJournalTable.JournalId
        {

            childNode = doc.createElement(fieldId2name(tableName2Id("InventJournalTrans"),6));//InventJournalTrans,ItemId));
            labelAttribute = doc.createAttribute("Item  ID");//error here because there is blankspace 
            labelAttribute.value(InventJournalTrans.ItemId);
            childNode.attributes().setNamedItem(labelAttribute);
            strValue  = strFmt("%1",(_recordChild.(fieldnum(InventJournalTrans,ItemID))));
            childNode.innerText(strValue);
            parentNode.appendChild(childNode);
        }
    }

so it should be

private void XMLChilddata(DmsTableFieldMapping _mapping,common _recordChild)
{
    str                     strValue;
    XmlAttribute            labelAttribute;
    //InventJournalTable      InventJournalTableloc;
    InventJournalTrans      InventJournalTrans;
    //SysDictField            dict;

    if(_recordChild.TableId == InventJournalTable.TableId)
    {
        while select ItemID
            from InventJournalTrans
                where InventJournalTrans.JournalId == InventJournalTable.JournalId
        {

            childNode = doc.createElement(fieldId2name(tableName2Id("InventJournalTrans"),6));//InventJournalTrans,ItemId));
            labelAttribute = doc.createAttribute("Item ID");//so no error now
            labelAttribute.value(InventJournalTrans.ItemId);
            childNode.attributes().setNamedItem(labelAttribute);
            strValue  = strFmt("%1",(_recordChild.(fieldnum(InventJournalTrans,ItemID))));
            childNode.innerText(strValue);
            parentNode.appendChild(childNode);
        }
    }

Tuesday, 24 November 2015

cross company and change company

DataAreaId                  localDataArea = curext();

    InventItemOrderSetupType    setupType   = InventItemOrderSetupType::Invent;
    InventJournalCheckPost      journalCheckPost = new InventJournalCheckPost();

    //change company
    changeCompany(_DMS_IMEIDelinkingTable.DataArea)
    {

        ttsbegin;
        this.progressbar();
        inventJournalTable.clear();
        num = new NumberSeq();
        num = NumberSeq::newGetNum(InventParameters::numRefTransferId());

        inventJournalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().LossProfitJournalNameId));
        inventJournalTable.DMSRequestID = _DMS_IMEIDelinkingTable.DMSRequestID;
        inventJournalTable.Description  = "";
        inventJournalTable.insert();

        while select crossCompany DMSCurrentItermID, IMEI, DMSNewItemID from  IMEIDelinkingLine
            where IMEIDelinkingLine.DMSRequestID == _DMS_IMEIDelinkingTable.DMSRequestID
                && IMEIDelinkingLine.dataAreaId  == localDataArea
        {
            inventJournalTrans.clear();
//do the business logic
        }


change company : it changes the from current company to the current company.

cross company : normally when we select the table it will display the data related to company  id .

when  can select the cross company it select all the company records from the table and we can use it for flteration.

cross company in query

 this.query().allowCrossCompany(true);

        this.query().dataSourceTable(tablenum(InventJournalTable)).addRange(fieldNum(InventJournalTable,RequestID)).value(parmId);

        query = this.query();

Sunday, 11 October 2015

data migration process from one db to other DB

Data Migration Process
                                                Data migration is the process of migrating data from one database to another database (i.e importing data from source db to target db) by mapping the fields of source and destination tables respectively.
Here we followed the process using SQL server integration tool (i.e DB to DB importing process )
à Open Visualstudio select new project Templates > Business Intelligence >Integrated services
àIn integrated services >select the Solution Explorer >Go to SSIS Packages >new Package >rename the package
àOn the left hand side select the dataflow >drag & drop the OLE DB source component and OLE DB destination component.
àNow goto OLE DB Source> double click on it > Select the server name, database name & table name (i.e from this server, database & table, the data is ready to import on destination) then click ok
Note: while clicking ok please check the columns are marked or not
Example: Here we selected servername as INSVR07, DB as TTC_2009, Sales Table, check test connection whether the connection is succeeded or not
àSelect the Source component, map it to the destination component (i.e select source component then one blue down arrow appears on it just simply drag it on the destination component)
àNow Double Click on the destination > Select the server name, database name & table name (i.e to this server, database, table the data is going to import from the source) now click on mapping and Map the both fields and click ok
Example: Here we selected servername as INSVR07, DB as TTC_2012, Sales Table, check test connection whether the connection is succeeded or not
àif any error symbols shows it means mapping doesn’t done correctly or if no any errors occurs mapping was done successfully
àFinally, Select both source and destination components then right click > Select execute Task
  If it shows any error occurs check it in process tab.

àNow the data is imported from source to destination tables

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...