Thursday, 10 March 2016

Performance tip: Caching display method

One significant side-effect of using display methods can be the impact on performance. Particularly when complex methods are used to calculate values being shown on grids, a visible slow-down in form performance can be experienced. This is largely due to the fact that the methods are often run repeatedly even when no reason is apparent and the values are unchanged.

To alleviate this, display methods on tables can be cached by using the cacheAddMethod method of the datasource object. To enable caching of a display method, call cacheAddMethod() from the initmethod of the datasource. This ensures that the display will only be calculated when necessary and can result in a significant performance improvement.
public void init()
{
    super();
    // Enable caching of the document handling display fields
    dirPartyTable_ds.cacheAddMethod(tablemethodstr(DirPartyTable, primaryPhone));
}

Tuesday, 8 March 2016

Import table values from excel - PO creation

static void CreatePO(Args _args)
{
NumberSeq numseq;
PurchTable purchTable;
PurchLine purchLine;
PurchFormLetter purchFormLetter;
Dialog dialog;
DialogField dialogField;

int i,j;
    CCADOConnection  adoConnection;
    CCADOCommand    adoCommand;

    CCADORecordSet   adoRecordSet;
    CCADOFields      adoFields;
    CCADOField       adoField;

;
    adoConnection = new CCADOConnection();
    adoRecordSet = new CCADORecordSet();
    adoConnection.open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= 'c:\\file.xls' ;Extended Properties='Excel 8.0;HDR=No;IMEX=1'");
    adoCommand = new CCADOCommand();
    adoCommand.activeConnection(adoConnection);
    adoCommand.commandText(@"SELECT * FROM [SHEET1$]");



ttsbegin;
numseq = NumberSeq::newGetNumFromCode(PurchParameters::numRefPurchId().NumberSequence,true);

//initialize purchase order values
purchTable.initValue();
purchTable.PurchId = numseq.num();
purchTable.OrderAccount = '1002';
purchTable.initFromVendTable();

if(!purchTable.validateWrite())
{
throw Exception::Error;
}
purchTable.insert();

//Inserting Purchase Lines
  adoRecordSet = adoCommand.execute();
  while(!adoRecordSet.EOF())
    {
        adoFields = adoRecordSet.fields();
         i=0;
   
        while(i<adoFields.count()-1)
        {

        purchLine.clear();
        purchLine.PurchId = purchTable.PurchId;

        purchline.ItemId = adoFields.itemIdx(i).value();
        i++;
        purchline.PurchQty = adoFields.itemIdx(i).value();
        purchLine.createLine(true,true,true,true,true,false);

        }
        adoRecordSet.recordSet().moveNext();

    }
//invoiceing the entries using purchFormLetter Class

purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchTable,"Inv_"+purchTable.PurchId,systemdateget());

if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice)
{
info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId));
}
}

Store image in table

Create a table with Container Datatype
IN form take a method getImage() write the following code.
_path = "Image path"
void getImage()
{
Bindata binData = new BinData();
FilePath _path;
ImageStore _ImageStore;

;
_path = "D:\India_flag.gif"; // file path 
binData.loadFile(_path);

_ImageStore.ItemImage = binData.getData();
_ImageStore.doInsert();
}
__
take a button and call this method there: 
void clicked()
{
super();

element.getImage();
ImageStore_ds.executeQuery();

}

How to call Print JobSettings in SSRS

Args args = new Args(reportstr(POSReciept)); 
PrintJobSettings printJobSettings; 
ReportRun reportRun; 
; 
printJobSettings = new PrintJobSettings(); 
printJobSettings.SetTarget(PrintMedium::Printer); printJobSettings.suppressScalingMessage(true); 

reportRun = new ReportRun(args); 
reportRun.setTarget(PrintMedium::Printer); 
reportRun.init(); reportRun.run();

Code to Open Printer Destination Dialog and select option for SSRS

Printer Destination Dialog

When  you click the button, it opens the Printer Destination Dialog for your report.

void clicked()
{
SRSPrintDestinationSettings             printSettings;
     printSettings = new SRSPrintDestinationSettings();

    super();

    if(SrsReportRunUtil::showSettingsDialog(printSettings))
    {
        SalesTable.ItemLabelPrintSettings = printSettings.pack();
    }
}

Code to Run report using the Printer setting option :

void clicked()
{
     ItemLabelController controller  = new ItemLabelController();
     Args  args = new args();
    container                   printSettingsLoc;
    if(Global::hasMenuItemAccess(menuitemOutputStr(ItemLabels),MenuItemType::Output))
    {
        args.record(SalesTable);
        controller.parmArgs(args);
        controller.parmReportName(ssrsReportStr(ItemLabelReport,Report));
        controller.parmShowDialog(false);
        if(SalesTable.ItemLabelPrintSettings)
        {
            printSettingsLoc = SalesTable.ItemLabelPrintSettings;
            controller.setPrinterSettings(printSettingsLoc);
        }
        controller.parmReportContract().parmPrintSettings().printMediumType(conPeek(printSettingsLoc,3));
        controller.parmReportContract().parmPrintSettings().overwriteFile(true);
        controller.parmReportContract().parmPrintSettings().fileName(conPeek(printSettingsLoc,20));

        controller.startOperation();
    }
}

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

Controller Class for the report :
class ItemLabelController extends SrsReportRunController
{
    container                   printerSettings;
    SRSPrintDestinationSettings printDestinationSettings;

}

protected void prePromptModifyContract()
{
    ItemLabelContract contract;
    PurchParmTable      purchParmTable;
    SalesTable          salesTable;//Bju_CIT_WMS013_ReturnRegistrationInReturnFor_11Jan
    contract = this.parmReportContract().parmRdpContract() as ItemLabelContract;
    if(this.parmArgs() && this.parmArgs().record().TableId  ==  tableNum(PurchParmTable))//Bju_CIT_WMS013_ReturnRegistrationInReturnFor_11Jan
    {
        purchParmTable = this.parmArgs().record();
        contract.parmPurchParmTable(purchParmTable.parmId);
        contract.parmTableRefId(purchParmTable.TableRefId);
    }
    //Bju_CIT_WMS013_ReturnRegistrationInReturnFor_11Jan
    if(this.parmArgs() && this.parmArgs().record().TableId  ==  tableNum(SalesTable))
    {
        salesTable = this.parmArgs().record();
        contract.parmSalesTable(salesTable.salesid);
    }
    //Bju_CIT_WMS013_ReturnRegistrationInReturnFor_11Jan
}

public void setPrinterSettings(container _settings)
{
    printerSettings = _settings;

    printDestinationSettings = new SRSPrintDestinationSettings();
    if (conlen(printerSettings) > 0)
    {
        printDestinationSettings.unpack(printerSettings);

    }
}



Friday, 4 March 2016

Filter Datasource in form

Class Declaration of Form :

QueryBuildRange qbrYear, qbrMake, qbrModel;

Data Source Init method

public void init()
{
    super();
    qbrYear =   this.query().dataSourceName('FitmentGuide').addRange(fieldNum(FitmentGuide,Year));
    qbrMake =   this.query().dataSourceName('FitmentGuide').addRange(fieldNum(FitmentGuide,Make));
    qbrModel =   this.query().dataSourceName('FitmentGuide').addRange(fieldNum(FitmentGuide,Model));
}

Data Source Execute Query

public void executeQuery()
{
    if(YearFilter.valueStr())
        qbrYear.value(queryValue(YearFilter.valueStr()));
    else
        qbrYear.value(queryValue(null));
    if(MakeFilter.valuestr())
        qbrMake.value(queryValue(MakeFilter.valuestr()));
    else
        qbrMake.value(queryValue(null));
    if(ModelFilter.valuestr())
        qbrModel.value(queryValue(ModelFilter.valuestr()));
    else
        qbrModel.value(queryValue(null));

    super();
}



2nd Way : If you dont have  data source for which you want to keep range but it is related to the tables in form 

Class Declaration of Form :

QueryBuildDataSource            qbrmatchingorders,qbrsalestable
Data source Init method ( to which you want to add relation and range)

public void init()
{
    super();
    qbrmatchingorders   =   MatchingOrders_q.dataSourceTable(tableNum(MatchingOrders));
    qbrsalestable   =   qbrmatchingorders.addDataSource(tableNum(SalesTable));
    qbrsalestable.joinMode(JoinMode::ExistsJoin);
    qbrsalestable.relations(true);
}

Data Source Execute Query

public void executeQuery()
{
    QueryBuildRange                 qbrmatchbackkeycode;
    qbrmatchbackkeycode = qbrsalestable.addRange(fieldNum(SalesTable,MatchbackKeycode));
    qbrmatchbackkeycode.value(queryValue(""));
    super();
}



Thursday, 3 March 2016

Auto Reserve using x++ code

static void autoReserve(Args _args)
{
    InventUpd_Reservation   reservation;
    SalesLine               salesLine = SalesLine::findInventTransId('013371');
    InventMovement          movement = InventMovement::construct(salesLine);

    InventQty               reserveQuantity = salesLine.QtyOrdered - abs(movement.transIdSum().reserved());

    if (reserveQuantity > 0)
    {
        reservation = InventUpd_Reservation::newMovement(
                                        movement,
                                        -reserveQuantity,
                                        true /*mayBeReduced */);

        reservation.updateNow();
    }
}