Tuesday, December 28, 2010

Creating a SalesOrder through .net applications or BC classes

Sometimes it would be necessary for us to create the SalesOrder through the .net application or some third party application at that time we need to make use of BC classes to create SalesOrder. Here is a small snipeet for creating the salesOrder through AXBC classes.

static void salesOrder(Args _args)
{   

       AxSalesTable axSalesTable;
       AxSalesLine axSalesLine;
       AxInventDim_SalesLine axInventDim;
       NumberSequenceReference numberSequenceReference;
       NumberSeq numSeq;
       SalesTable salesTable;
       SalesId salesId;
       ;
       ttsbegin;
       numberSequenceReference = SalesParameters::numRefSalesId();
       numSeq = new NumberSeq();
       numSeq = NumberSeq::newGetNum(numberSequenceReference,true);
       salesId = numSeq.num();
       axSalestable = AxSalesTable::construct();
       axSalesTable.parmCustAccount('100123');
       axSalesTable.salesTable().initFromCustTable();
       axSalesTable.salesTable().initValue();
       axSalesTable.salesTable().initFromContactInfo();
      axSalesTable.parmSalesId(salesId);
       if(!axSalesTable.salesTable().validateWrite())
       {
            numSeq.abort();
            break;
       }
       else
       {
           numSeq.used();
           axSalesTable.save();
        }
        SalesTable = SalesTable::find(salesId);
        axSalesLine = AxSalesLine::construct();
        axSalesLine.parmSalesId(salesId);
        axSalesLine.salesLine().initValue();
        axSalesLine.salesLine().initFromSalesTable(SalesTable);
        axSalesLine.parmItemId('1121');
        axSalesLine.salesLine().initfrominventTable();
        axInventDim = AxInventDim_SalesLine::newAxSalesLine(axSalesLine);
        axInventDim.parmInventSizeId('42');
        axInventDim.parmInventLocationId("21");
        axInventDim.parmConfigId("HD");
        axInventDim.parmInventColorId('01');
        axInventDim.parmInventSiteId('2');
        axInventDim.setInventDimId();
        axSalesLine.axInventDim(axInventDim);
        axSalesLine.save();
        ttscommit;
    
}

Getting the list of datasource from the form

Sometimes may be there would be need to get the names of the datasources used in the form . Here is a small snippet that would get you the list of the data source 

static void datasources(Args _args)
{
        FormRun formRun;
        FormBuildDataSource fbds;
        Args args = new Args();
        Counter i;
         ;
         args.name('Salestable'); //FormName
         formRun = classFactory.formRunClass(args);
         for (i = 1; i <= formRun.form().dataSourceCount(); i++)
         {
          fbds = formRun.form().dataSource(i);
          info(new DictTable(fbds.table()).name());
          }
}

The output of the following code is

Thursday, December 23, 2010

Creating a new form using code

static void CreateForm_usingCode(Args _args)
{
    Form form;
    FormRun formRun;
    Args args;
    FormBuildDesign formBuildDesign;
    FormBuildControl formBuildControl;
    FormBuildTabControl formBuildTabControl;
    FormBuildTabPageControl formBuildTabPageControl;
    FormBuildGridControl formBuildGridControl;
    FormBuildDatasource formBuildDatasource;
    FormBuildStringControl formString;
    ;
    form = new Form();
    formBuildDatasource = form.addDataSource(tableStr(CustTable));
    formBuildDesign = form.addDesign('design');
    formBuildTabControl = formBuildDesign.addControl(FormControlType::Tab, 'Tab1');
    formBuildTabPageControl = formBuildTabControl.addControl(
                                                    FormControlType::TabPage,  TabPage');
    formBuildGridControl = formBuildTabPageControl.addControl(FormControlType::Grid, 'Grid');
    formString = formBuildGridControl.addDataField(formBuildDatasource.id(),
                                                                                      fieldNum (CustTable,           Accountnum));
    formString.label("Customer Account");
    args = new Args();
    args.object(form);
    formRun = classFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
}

Getting the List of Private and Shared projects from the Projects node using X++.

For retreiving the list of projects we cannot use Treenode. We should first use infolog.projectrootnode() to get the root node for projects and then proceed with the treenode iterator to get the list of the rest. Below is the code that will display the list of Private and Shared Projects from the project node.

static void GetProjects(Args _args)
{
     ProjectListNode projectListNode;
     treenodeIterator iterator,projectiterator;
     TreeNode treenodeprivate,treenodeprivateprojects,treenodeShared,treenodesharedprojects;
     int i;
     ;
     projectListNode = infolog.projectRootNode();
     treenodeprivate = projectListNode.AOTfirstChild();
     iterator =treenodeprivate.AOTiterator();
    setprefix("Private projects");
    for(i = 1; i<=treenodeprivate.AOTchildNodeCount();i++)
    {
            treenodeprivateprojects = iterator.next();
            info(findproperty(treenodeprivateprojects.AOTgetProperties(),"Name"));
     }
     treenodeshared = infolog.projectRootNode().AOTfindChild('Shared');
     projectiterator = treenodeshared.AOTiterator();
     setprefix("Shared Projects");
     for(i=1; i<= treenodeshared.AOTchildNodeCount();i++)
     {
            treenodesharedprojects = projectiterator.next();
            info(findproperty(treenodesharedprojects.AOTgetProperties(),"Name"));
      }
}
Attached is the Output of the following Job:


It has been some time I have not updated my blog....Well was bit busy... Here we go....I am back ...Watch Out Intresting Posts coming your way....Happy DAXing... :)