Thursday, July 17, 2025

Upload File from local system in a form

 Actions to be done at 3 stages 

1) Create Fileupload item by right clicking on design as shown in image below

2)Change Properties especially Fileuploadstrategyclass to "FileUploadTempStorageStrategy" as shown in image below.


3) After that to store file in Docref use logic in OnUploadCompleted() method

[Form]
public static class DaxTestingForm extends SysLookupMultiSelectGrid
{
    #characters
    [Control("Custom")]
    class ImageUpload
    {
        /// <summary>
        ///
        /// </summary>
        public void OnUploadCompleted()
        {
            FileUploadTemporaryStorageResult    result = this.getFileUploadResult() as FileUploadTemporaryStorageResult;
              
            super();

 

            if(result && result.getUploadStatus())
            {
                str fileName = "YourFileName.pdf"; //Insert the name of the attachchment

 

                using(System.IO.MemoryStream stream = result.openResult() as System.IO.MemoryStream)
                {
                    DocuRef docuRef = DocumentManagement::attachFile(
                            MainAccountTable.TableId, // The Table Id that will be linked to the the attachment
                    MainAccountTable.RecId,   //The RecId of the record that will be linked to the attachment
                    curext(),
                        DocuType::typeFile(),//Input here the attachment type
                    stream,
                            fileName,
                            null,
                            fileName);
                }
            }

 

            
        }
        
    }

 }

Otuput:-


Monday, July 14, 2025

Multi selection lookup in grid

 [Form]

public class Form1 extends FormRun

    

     SysLookupMultiSelectCtrl msCtrl;


    [Control("String")]

    class MyTablenew_FieldString2

    {

        

        public void lookup()

        {

           

           

            Query query = new Query();

            QueryBuildDataSource qbds = query.addDataSource(tableNum(MainAccount));         

            qbds.fields().addField(fieldNum(MainAccount, MainAccountId));

            qbds.orderMode(OrderMode::GroupBy);

            qbds.addGroupByField(fieldNum(MainAccount, MainAccountId));

            qbds.fields().dynamic(NoYes::No);

            msCtrl = SysLookupMultiSelectCtrl::constructWithQuery(element,MyTablenew_FieldString2,query);

            

            msCtrl.set(msCtrl.getSelectedFieldValues());

        }


        

        public boolean modified()

        {

            boolean ret;

        

            ret = super();

            MyTablenew buffer=element.dataSource("MyTablenew").cursor();

            buffer.FieldString2=con2Str(msCtrl.getSelectedFieldValues(),";");

        

            return ret;

        }

    }



}


Output:-






Friday, July 11, 2025

Get Mainaccount lookup thorugh lookup code

 Query query = new query();

   QueryBuildDataSource qbds; 
   QueryBuildRange qbr;
   SysTableLookup  sysTableLookup;
   sysTableLookup= SysTableLookup:: newParameters (tableNum (MainAccount),this);
   sysTableLookup.addLookupfield (fieldNum (MainAccount, MainAccountId));
   sysTableLookup.addLookupfield (fieldNum (MainAccount, Name));
   qbds = query.addDataSource(tableNum (MainAccount));
   qbds.orderMode(OrderMode::GroupBy);
   qbds.addGroupByField(fieldNum(MainAccount, MainAccountId));
   qbds.addGroupByField(fieldNum(MainAccount, Name));
   //qbr = qbds.addRange(fieldNum (MainAccount, LedgerChartOfAccounts)); 
   //qbr.value(queryValue (LedgerChartOfAccounts::current()));
   sysTableLookup.parmQuery(query); 
   sysTableLookup.performFormLookup();

Thursday, July 10, 2025

Create and post Free text invoice for customer through code X++

 internal final class TestFreeTextInvoices

{

    /// <summary>

    /// Class entry point. The system will call this method when a designated menu

    /// is selected or when execution starts and this class is set as the startup class.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

   

    public static CustInvoiceTable    custInvoiceTable;

    public static CustInvoiceLine custInvoiceLine;

    public static void main(Args _args)

    {

        

        

        TestFreeTextInvoices caption = new TestFreeTextInvoices();

        caption.createCustInvoiceHeader(systemDateGet(),(systemDateGet()+10),'US-001','10');

        if(custInvoiceTable)

        {

            caption.createCustInvoiceLine(custInvoiceTable,'test description','ALL','CA',1,1,'110110');

            if(custInvoiceLine)

            {

                caption.postCustInvoice(custInvoiceTable);

            }

        }

        

        

    }

 

    public CustInvoiceTable createCustInvoiceHeader(TransDate _invoiceDate , DueDate _dueDate, CustAccount _custAccount = '', CustGroupId _custGroup = '')

    {

        CustTable        custTable;

 

        custTable = CustTable::find(_custAccount);

        custInvoiceTable.initFromCustTable(custTable);

        custInvoiceTable.CustGroup                          = _custGroup;

        custInvoiceTable.OrderAccount                       = _custAccount;

        custInvoiceTable.InvoiceAccount                     = _custAccount;

        custInvoiceTable.modifiedField(fieldNum(CustInvoiceTable, OrderAccount));

        custInvoiceTable.InvoiceDate                        = _invoiceDate;

        custInvoiceTable.DueDate                            = _dueDate;

        if(custInvoiceTable.validateWrite())

        {

            custInvoiceTable.insert();

        }

 

        return custInvoiceTable;

    }

    

    public void createCustInvoiceLine(CustInvoiceTable _custInvoiceTable, TransactionTextLarge _description = '', TaxItemGroup _taxItemGroup = '', TaxGroup _taxGroup = '', InvoiceQuantity _qty = 1, InvoiceUnitPrice _unitPrice = 1, str MainAccount ='')

    {

        

        LineNum         lineNum;

        

        custInvoiceLine.initValue();

        custInvoiceLine.initFromCustInvoiceTable(_custInvoiceTable);

        

        custInvoiceLine.Description      = _description;

        custInvoiceLine.TaxItemGroup     = _taxItemGroup;

        custInvoiceLine.TaxGroup         = _taxGroup;

        custInvoiceLine.ParentRecId      = _custInvoiceTable.RecId;

        custInvoiceLine.Quantity         = _qty;

        custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, Quantity));

        custInvoiceLine.UnitPrice        = _unitPrice;

        custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, UnitPrice));

        custInvoiceLine.AmountCur        = custInvoiceLine.Quantity * custInvoiceLine.UnitPrice;

        custInvoiceLine.LedgerDimension  = TestFreeTextInvoices::findLedgerDimensionByMainAccount(MainAccount);

        

        if(custInvoiceLine.validateWrite())

        {

            custInvoiceLine.insert();

        }

    }

 

    public static RecId findLedgerDimensionByMainAccount(str MainAccount)

    {

        MainAccount mainAccounttest = MainAccount::findByMainAccountId(MainAccount, true);

        DimensionAttributeValueCombination dimensionAttributeValueCombination;


        select firstOnly dimensionAttributeValueCombination

             where dimensionAttributeValueCombination.MainAccount == mainAccounttest.RecId && dimensionAttributeValueCombination.LedgerDimensionType==LedgerDimensionType::DefaultAccount;

        

        

        return dimensionAttributeValueCombination.RecId;

    }

 

    public void postCustInvoice(CustInvoiceTable _custInvoiceTable)

    {

        CustPostInvoice custPostInvoice;

 

        custPostInvoice = new CustPostInvoice(_custInvoiceTable);

 

        ttsbegin;

        custPostInvoice.run();

        ttscommit;

    }

}

OutPut:-



Miscellaneous code

 1) Dimensions  view :- To get all dimension values use this views

DimensionAttributeLevelValueAllView  ---ldger 

DefaultDimensionView   ------------------------default 


---------------------------------- 

2) To access Global declared buffers in methods 

Use "element.buffer" by  this one can get all buffers from global level.  

 

Note:- By just using element. You won't see the buffers list , just copy and paste and save you will see no errors 

Upload File from local system in a form

 Actions to be done at 3 stages  1) Create Fileupload item by right clicking on design as shown in image below 2)Change Properties especiall...