Tuesday, 15 October 2013

UI Builder class in Dynamic AX

http://vasantharivali.wordpress.com/ - Filter second lookup based on first value

UI Builder class
Step1 : Your Class must extends SrsReportDataContractUIBuilder
class SimpleDemoUIBuilder extends SrsReportDataContractUIBuilder
{
DialogField dialogEmplId;
DialogField dialogName;
boolean enable;
SimpleDemoContract contract;
}// two fields emplId and Name will reflect in the lookup in dialog form at the time of report opening.
Step2 : Override the build method
public void build()
{
contract = this.dataContractObject();
dialogEmplId = this.addDialogField(methodStr(SimpleDemoContract, parmEmplId),contract);
}// this method used for adding the field  which is from contract class.
Step3 : Write this below code to get lookup
private void emplIdLookup(FormStringControl emplIdlookup)
{
Query query = new Query();
QueryBuildDataSource qbds_EmplTable;
SysTableLookup sysTableLookup;
// Create an instance of SysTableLookup with the current calling form control.
sysTableLookup = SysTableLookup::newParameters(tableNum(FilterDemo), emplIdlookup);
// Add fields to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(FilterDemo,EmplId));
sysTableLookup.addLookupfield(fieldNum(FilterDemo,Name));
qbds_EmplTable = query.addDataSource(tableNum(FilterDemo));
sysTableLookup.parmQuery(query);
// Perform the lookup
sysTableLookup.performFormLookup();
}
Step4 : Override this method
public void getFromDialog()
{
contract = this.dataContractObject();
super();
}
Step5 : Override this method
public void initializeFields()
{
contract = this.dataContractObject();
}
Step6 : Override this method
public void postBuild()
{
super();
dialogEmplId = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(SimpleDemoContract,parmEmplId));dialogEmplId.registerOverrideMethod(methodStr(FormStringControl, lookup),
methodStr(SimpleDemoUIBuilder,emplIdLookup), this);dialogEmplId.lookupButton(2);
}

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

class CITCustPaymImportUIBuilder extends SysOperationAutomaticUIBuilder
{
    Dialog      dlg;
    DialogField     dialogCustAcc;
    DialogField     dialogFilePath;
    DialogField     dialogPostingDate;
    DialogField     dialogJournalNum;
    str FileUploadName = 'FileUpload';
    private const str OkButtonName = 'Upload';
    str fileUrl;
    FileUploadBuild  dialogFileUpload;
    //dialogField     dialogFileUpload;


    CITCustPaymImportContract   contract;
    public void build()
    {
        DialogGroup dlgGrp;
        contract = this.dataContractObject();
        

        //get the current dialog
        dlg = this.dialog();

        dialogCustAcc = this.addDialogField(methodStr(CITCustPaymImportContract, parmCustAccount),contract);
        dialogCustAcc.value('');
        //dialogFilePath = this.addDialogField(methodStr(CITCustPaymImportContract, parmFilePath),contract);
        dialogPostingDate = this.addDialogField(methodStr(CITCustPaymImportContract, parmPostingDate),contract);
        dialogPostingDate.value(systemDateGet());
        dialogJournalNum = this.addDialogField(methodStr(CITCustPaymImportContract, parmJournalNum),contract);
        //make required modifications to the dialog
        dlgGrp = dlg.addGroup('File Upload');
        dlgGrp.columns(2);
        
        FormBuildControl formBuildControl = dlg.formBuildDesign().control(dlgGrp.name());
        
        dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), FileUploadName);
        dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
        dialogFileUpload.fileNameLabel("@SYS308842");
        dialogFileUpload.resetUserSetting();
        dialogFileUpload.style(FileUploadStyle::MinimalWithFilename);
        dialogFileUpload.fileTypesAccepted('.xlsx');
    }

    public void dialogPostRun(DialogRunbase _dialog)
    {
        //super(_dialog);
        FileUpload fileUpload = this.getFormControl(_dialog, FileUploadName);
       // fileUpload.notifyUploadCompleted += eventhandler(dlg.uploadCompleted);
        //this.setDialogOkButtonEnabled(_dialog, false);
        FileUploadTemporaryStorageResult fileUploadResult = fileUpload.getFileUploadResult() as FileUploadTemporaryStorageResult;
        info(strfmt("-%1",fileUploadResult));
        if (fileUploadResult != null && fileUploadResult.getUploadStatus())
        {
            fileUrl = fileUploadResult.getDownloadUrl();
            info(strfmt("%1", fileUrl));
            contract.parmFilePath(fileUrl);
            
            
        }
    }

    protected FormControl getFormControl(DialogRunbase _dialog, str _controlName)
    {
        return _dialog.formRun().control(_dialog.formRun().controlId( _controlName));
    }

    private void setDialogOkButtonEnabled(DialogRunbase _dialog, boolean _isEnabled)
    {
        FormControl okButtonControl = this.getFormControl(_dialog, OkButtonName);

        if (okButtonControl)
        {
            okButtonControl.enabled(_isEnabled);
        }
    }

    public void run()
    {
        
        try
        {
            ttsbegin;
            FileUpload fileUploadControl = this.getFormControl(dlg, FileUploadName);
            FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult() as FileUploadTemporaryStorageResult;
            info(strfmt("-%1",fileUploadResult));
            if (fileUploadResult != null && fileUploadResult.getUploadStatus())
            {
                fileUrl = fileUploadResult.getDownloadUrl();
                info(strfmt("%1", fileUrl));
            
            
            }
            ttscommit;
        }
        catch (Exception::Deadlock)
        {
            retry;
        }
    }

    public void postBuild()
    {
        contract            =   this.dataContractObject();
        dialogCustAcc = this.bindInfo().getDialogField(
        this.dataContractObject(), methodStr(CITCustPaymImportContract, parmCustAccount));
        dialogFilePath = this.bindInfo().getDialogField(
        this.dataContractObject(), methodStr(CITCustPaymImportContract, parmFilePath));
        dialogPostingDate = this.bindInfo().getDialogField(
        this.dataContractObject(), methodStr(CITCustPaymImportContract, parmPostingDate));
        dialogJournalNum = this.bindInfo().getDialogField(
        this.dataContractObject(), methodStr(CITCustPaymImportContract, parmJournalNum));
        
    }

    private void custAccLookup(FormStringControl custAcclookup)
    {
        /*Query query = new Query();
        QueryBuildDataSource qbds_CustTable;
        QueryBuildRange         qbrBlocked;
        SysTableLookup sysTableLookup;
        
        // Create an instance of SysTableLookup with the current calling form control.
        sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), custAcclookup);
        // Add fields to be shown in the lookup form.
        sysTableLookup.addLookupfield(fieldNum(CustTable,AccountNum));
        //sysTableLookup.addLookupfield(fieldNum(CustTable,Name));
        sysTableLookup.addLookupMethod(tableMethodStr(CustTable,Name));
        qbds_CustTable = query.addDataSource(tableNum(CustTable));
        //this.query().dataSourceTable(tablenum(PurchTable)).addRange(fieldnum(PurchTable, PurchStatus)).value(strfmt('!%1,!%2',enum2str(PurchStatus::Canceled),enum2str(purchstatus::Invoiced)));
        //qbds_CustTable.addRange(fieldNum(CustTable, Blocked)).value(enum2str(CustVendorBlocked::All),enum2str(CustVendorBlocked::Payment));
        qbds_CustTable.addRange(fieldNum(CustTable, Blocked)).value(strfmt('!%1,!%2',enum2str(CustVendorBlocked::All),enum2str(CustVendorBlocked::Payment)));
        sysTableLookup.parmQuery(query);
        // Perform the lookup
        sysTableLookup.performFormLookup();*/
        CustTable::lookupCustomer(custAcclookup, curExt());
    }

    public void postRun()
    {
        super();

        //Register overrides for form control events
        dialogCustAcc.registerOverrideMethod(
        methodstr(FormStringControl, lookup),
        methodstr(CITCustPaymImportUIBuilder, custAccLookup),
        this);
    }

    /// <summary>
    ///
    /// </summary>
    public void getFromDialog()
    {
        
        FileUpload fileUploadControl = dlg.formRun().control(dlg.formRun().controlId(FileUploadName));
          
        FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult() as FileUploadTemporaryStorageResult;
        if (fileUploadResult != null && fileUploadResult.getUploadStatus())
        {
            fileUrl = fileUploadResult.getFileId();
        }
        contract.parmFilePath(fileUrl);
        super();
    }


}

No comments:

Post a Comment