Wednesday, 29 March 2017

Show Documents Icon in Listpage

Show Documents Icon in Listpage

Show document icon in list page, if documents attached to the specific record

Scenario:  Display document icon if user attached any document to the specific record in Listpage.
Below are the steps to bring it in real..

1    1)      Create a below display method in table
display smmDocIconNum showDocHandIcon()
{
    #macrolib.resource

    if ((select firstonly docuRef where docuRef.RefCompanyId  == this.DataAreaId && docuRef.RefTableId ==                this.TableId && docuRef.RefRecId == this.RecId).RecId)
    {
        return #RES_NODE_DOC;
    }

    return #RES_AM_NEW;
}

2     2)      Create a window control in form listpage  and point the table method in control properties.
3     3)      Create window control mouseUp method and paste the below code

int mouseUp(int _x, int _y, int _button, boolean _ctrl, boolean _shift)
{
    int ret;

    ret = super(_x, _y, _button, _ctrl, _shift);

    smmUtility::openSmmDocHandling(salesQuotationTable, element);

    return ret;
}


(I took SalesQuotationtable as an example)

Happy coding!

Copy data from one company to other companies using X++

Copy data from one company to other companies using X++

Overview:

The requirement is to copy BudgetExceltemplate table data from ‘02’ company to other companies. Before import in other companies must delete the dump data.

Code:

The below job will copy and create records from ‘02’ to other companies,

static void CopyDataacrossCmy(Args _args)
{
    //BudgetExcelTemplate is the customized table.
    // Need to copy BudgetExcelTemplate table data from '02' company to all the company
    // Change the table which you want to copy from based on your needs.

    BudgetExcelTemplate   BudgettableFrom, BudgettableTo, tabledelete;
    DataArea            dataareatbl;  

    // ProgressCounter
    #avifiles
    SysOperationProgress                 progressbar;
    int                                  totalRecords;
    #define.TITLE("Copying data to other companies...")
    ;

    select count(RecId) from BudgettableFrom;

    totalRecords = any2int(BudgettableFrom.RecId);
    progressbar  = SysOperationProgress::newGeneral(#aviUpdate, #TITLE, totalRecords);

    // Delete the dump data in other companies except the from company data.
    while select dataareatbl where dataareatbl.id != '02'
    {
         changecompany(dataareatbl.id)
         { 
             tabledelete.clear();           
            ttsBegin;
            delete_from tabledelete where tabledelete.dataAreaId == dataareatbl.id;
            ttsCommit;           
         }
    }   
    BudgettableFrom.clear();   
    // Copy data from 02 company to rest of the companies
    while select dataareatbl where dataareatbl.id != "02"
    {      
        while select BudgettableFrom
        {
            changecompany(dataareatbl.id)
            {
                BudgettableTo.clear();

                ttsbegin;
                buf2buf(BudgettableFrom, BudgettableTo);
                BudgettableTo.insert();
                ttscommit;
            }
            progressbar.incCount();
        }
       
        BudgettableFrom.clear();
    }

    progressbar.hide();

}

Happy coding!