Showing posts with label dynamics ax. Show all posts
Showing posts with label dynamics ax. Show all posts

Thursday, 23 January 2020

CONTRACT CLASS IN SYSOPERATION D365 CODE X++ DYNAMICS AX

Hi,
In the below post you will see the sysoperation framework contract class which can be used to run the class form the contract class.

/// <summary>
///myclass contract
/// </summary>
[DataContractAttribute]
class MyClassContract
{
    str                      packedQuery;
    ItemId itemid;
    InventLocationId locationid;
    InventSiteId siteId;
    InventQty qty;

    [DataMemberAttribute,
    AifQueryTypeAttribute('_packedQuery', querystr(MyClassQuery))
    ]
    public str parmQuery(str _packedQuery = packedQuery)
    {
        packedQuery = _packedQuery;
        return packedQuery;
    }

    public Query getQuery()
    {
        return new Query(SysOperationHelper::base64Decode(packedQuery));
    }

    public void setQuery(Query _query)
    {
        packedQuery = SysOperationHelper::base64Encode(_query.pack());
    }

    [DataMemberAttribute,  SysOperationControlVisibilityAttribute(false)]
    public ItemId parmItemid(ItemId _itemid = itemId)
    {
        itemid = _itemid;
        return itemid;
    }

    [DataMemberAttribute,  SysOperationControlVisibilityAttribute(false)]
    public InventSiteId parmSiteId(InventSiteId _siteId = siteId)
    {
        siteId = _siteId;
        return siteId;
    }

    [DataMemberAttribute,  SysOperationControlVisibilityAttribute(false)]
    public InventlocationId parmLocationId(InventlocationId _locationid = locationid)
    {
        locationid = _locationid;
        return locationid;
    }

}

********************************************************************************
for validation use below class
/// <summary>
/// desctiption
/// </summary>
[DataContractAttribute]
public class MyClassContract implements SysOperationValidatable
{
    str         query;
    TransDate   fromDate;
    TransDate   toDate;
    DataAreaId fromDateany,toDateany;
 
   [
        DataMemberAttribute,
        SysOperationLabelAttribute('@Label'),
        SysOperationDisplayOrderAttribute('1')
    ]
    public TransDate parmFromDate(TransDate _FromDate = FromDate)
    {
        FromDate = _FromDate;
        return FromDate;
    }
 
    [
        DataMemberAttribute,
        SysOperationLabelAttribute('@Label'),
        SysOperationDisplayOrderAttribute('2')
    ]
    public TransDate parmToDate(TransDate _toDate = toDate)
    {
        toDate = _toDate;
        return toDate;
    }

    [DataMemberAttribute, AifQueryTypeAttribute('_query', querystr(MyClassQuery))]
    public str parmQuery(str _query = query)
    {
        query = _query;
        return query;
    }

    public Query getQuery()
    {
        return new Query(SysOperationHelper::base64Decode(query));
    }

    public void setQuery(Query _query)
    {
        query = SysOperationHelper::base64Encode(_query.pack());
    }

    public static MyClassContract construct()
    {
        return new MyClassContract();
    }

    public boolean validate()
    {
        boolean ret = true;

        if (!this.parmFromDate() || !this.parmToDate())
        {
            ret = checkFailed("@@Label");
      }

        return ret;
    }

    protected void new()
    {
    }

}

Thanks!!!!!!!!!!!!!!!!11111

Controller class for SysoperatonFramework D365 Dynamics AX

Hi,
In the below post you will see the sysoperation framework controller class which can be used to run the class form the controller class.

[SysOperationJournaledParametersAttribute(true)]
class MyclassController extends SysOperationServiceController
{
    public static void main(Args args)
    {
        MyclassController controller;
        controller = MyclassController::newFromArgs(args);
     
        controller.startOperation();
    }
    public void new()
    {
        super();
   
        this.parmClassName(classStr(MyclassService));
        this.parmMethodName(methodStr(MyclassService, processClassMethod));
        this.parmExecutionMode(SysOperationExecutionMode::Synchronous);
        this.parmDialogCaption("@Label");
    }

    public ClassDescription caption()
    {
        return "@Label";
    }

    public static MyclassController  newFromArgs(Args _args)
    {
        MyclassController    controller;
           
        controller = new MyclassController();
        controller.initializeFromArgs(_args);
        return controller;
    }
}

Monday, 21 October 2019

TRY CATCH CODE IN DYNAMICS AX ,D365 ,AX 2012 CODE

TRY CATCH CODE IN DYNAMICS AX ,D365 ,AX 2012 CODE

System.Exception ex;
   try
   {
       FormletterService.Run()      
   }
   catch(Exception::CLRError)
   {
       ex = ClrInterop::getLastException();
        if (ex != null)
        {
           ex = ex.get_InnerException();
           if (ex != null)
           {
               throw error(ex.ToString());
           }
    }

}

Thanks,
Vikas Mehta.  

HOW TO GET GRID RECORDS IN DYNAMICS AX

HOW TO GET ALL THE GRID RECORDS IN DYNAMICS AX 

If you want to get the records of all the selected records in the grid on a form then write the below code in the clicked method of the form,
we can loop it for multiple records and can do any task required.

for (custInvoiceJourLoc = getFirstSelection(custInvoiceJour_ds);
custInvoiceJourLoc;
custInvoiceJourLoc = custInvoiceJour_ds.getNext())
{
// do some tasks here.

}

Thanks,
Vikas Mehta.

HOW TO GET DIMENSION FROM A RECORD

HOW TO GET DIMENSION FROM A RECORD

static void getCustomerDimension(Args _args)
{
    CustTable                         custTable = CustTable::find("Cust001");
    DimensionAttributeValueSetStorage dimStorage;
    Counter i;
      
    dimStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);
  
    for (i=1 ; i<= dimStorage.elements() ; i++)
    {
        info(strFmt("%1 = %2", DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name,        
                               dimStorage.getDisplayValueByIndex(i))); 
    }

}    

Thanks,
Vikas

Friday, 11 October 2019

D365 try catch how to get exact error message


HOW TO GET ERROR MESSAGE IN TRY CATCH


System.Exception exception;
try
{

}
catch(Exception::CLRError)
{
exception = CLRInterop::getLastException();
while(exception)
{
error( exception.get_Message() );
exception = exception.get_InnerException();
}
throw Exception::Error;
}

NOTE: Code inside the catch statement will only get executed of the tts level is zero.
Thanks,
Vikas Mehta

Wednesday, 9 October 2019

Code to change to Accounting currency in D365 Dynamics ax


Code to change to Accounting currency in D365 Dynamics ax 

Currency::amount(markupTrans.Value, markupTrans.CurrencyCode);

In the above code you can use any other table having corresponding values eg.salestrans.

Thanks,
Vikas Mehta.

Saturday, 9 February 2019

x++ code to post product recipt

x++ code to post product receipt
static void  postProdReceipt(Args _args)
{
    PurchTable  purchTable = PurchTable::find("000032");
    PurchFormLetter     purchFormLetter;
 
    purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
    purchFormLetter.update( purchTable,
                            "PO002",
                            systemDateGet(),
                            PurchUpdate::RegisteredAndServices,
                            AccountOrder::None,
                            false,
                            false);
 
    info("Done");
 
}

Saturday, 24 October 2015

AX 2012 SALES TRADE AGGREMENTS UPLOAD FROM EXCEL X++ CODE

AX 2012 SALES TRADE AGGREMENTS UPLOAD FROM EXCEL X++ CODE

        class VIK_SalesMaster_ExcelImport extends RunBaseBatch
        {
             DialogField                         dialogfile;
             FilenameOpen                        fileName;
             localmacro.CurrentList
              fileName
            endmacro
        }
     
       dialog
        protected Object dialog()
        {
            DialogRunbase  _dialog = super();
       
            _dialog.caption("Sales : Trade Aggrement Upload");
            dialogfile = _dialog.addField("FilenameOpen","Enter file path : ");
            dialogfile.value(fileName);
       
            return _dialog;
        }
     
       getFromDialog
        public boolean getFromDialog()
        {
            ;
            fileName = dialogfile.value();
            return true;
        }
     
       run
        public void run()
        {
            SysExcelApplication excel;
            SysExcelWorkbooks workbooks;
            SysExcelWorkbook workbook;
            SysExcelWorksheets worksheets;
            SysExcelWorksheet worksheet;
            SysExcelCells cells;
            COMVariantType type;
            int row =1;
            int _noofprints;
            CustName name;
            int i,j;
            //sales price upload
            str queryPricingMaster,itemId,existingItemIdsList,tempValue;
            ResultSet resultSet;
            InventTable inventTable;
            AifEntityKeyList                        keys;
            DD_HI_RRP_Staging                       RRPStaging;
            PricePriceDiscJournalService            PriceDiscSvc;
            PricePriceDiscJournal                   PriceDiscJour;
            PricePriceDiscJournal_PriceDiscAdmTrans PriceDiscJourAdmTrans;
            PricePriceDiscJournal_InventDim         PriceDiscJourDim;
            PriceDiscAdmTrans   _PriceDiscAdmTrans;
            //vikas
            PriceDiscAdmTable                   priceDiscAdmTable;
            PriceDiscAdmTrans                   PriceDiscAdmTrans;
            PriceDiscAdmName                    PriceDiscAdmName;
            PriceDiscJournalName                pricediscjournalName;
            NumberSeq journalNum;
            //sales price upload//
            str _relation,_accountcode,_accountselection,_itemcode,_temrelation,_unit,_curcode;
            real _from,_amtincur;
            date _todate,_fromdate;
            PriceType _pricetype;
            itemId tempItemId;
            AviFiles
            SysOperationProgress progress1 = new SysOperationProgress();
            ;
       
        //excel
        define.filename(fileName)
        excel = SysExcelApplication::construct();
        workbooks = excel.workbooks();
        try
        {
        workbooks.open(filename);
        }
        catch (Exception::Error)
        {
        throw error("File cannot be opened");
        }
       
       
                workbook = workbooks.item(1);
                worksheets = workbook.worksheets();
                worksheet = worksheets.itemFromNum(1);
                cells = worksheet.cells();
                type = cells.item(row+1, 1).value().variantType();
       
            //progress1.setCaption("Updation of pricing master is in progress…");
            //progress1.setAnimation(AviUpdate);
       
       
       
         ttsBegin;
       
            Select firstOnly  PriceDiscAdmName;
            priceDiscAdmTable.clear();
            priceDiscAdmTable.initFromPriceDiscAdmName(PriceDiscAdmName);
            journalNum      = NumberSeq::newGetNum(SalesParameters::numRefPriceDiscJournalNum());
            pricediscjournalName        =   journalNum.num();
            priceDiscAdmTable.JournalNum = pricediscjournalName;
            priceDiscAdmTable.insert();
       
           while (type != COMVariantType::VT_EMPTY)
        {
            row++;
            tempItemId  = cells.item(Row,5).value().bStr();
                // Set PriceDiscJourAdmTrans
                  while select forUpdate * from inventTable where inventTable.ItemId == tempItemId
                {
       
                   // progress1.setText(strfmt("Item ID  %1", tempItemId));
                    PriceDiscAdmTrans.clear();
                    PriceDiscAdmTrans.JournalNum        = pricediscjournalName;
                    PriceDiscAdmTrans.relation          = real2int(cells.item(Row,1).value().double()) ;//relation
                    PriceDiscAdmTrans.InventDimId       = "Allblank";
                    PriceDiscAdmTrans.DisregardLeadTime = NoYes::Yes;
                    PriceDiscAdmTrans.AccountCode       = real2int(cells.item(Row,2).value().double()) ; //account code
                    PriceDiscAdmTrans.AccountRelation   = cells.item(Row,3).value().bStr();     //account relation
                    PriceDiscAdmTrans.ItemCode          = real2int(cells.item(Row,4).value().double());
                    PriceDiscAdmTrans.ItemRelation      = cells.item(Row,5).value().bStr();         //item realtaion item id
                    PriceDiscAdmTrans.QuantityAmountFrom= cells.item(Row,6).value().double();        //from quantity
                    PriceDiscAdmTrans.UnitId            = cells.item(Row,7).value().bStr();            //unit id
                    PriceDiscAdmTrans.Amount            = cells.item(Row,8).value().double();         //Amount in Curr
                    PriceDiscAdmTrans.Currency          = cells.item(Row,9).value().bStr();        //currency code
                    PriceDiscAdmTrans.FromDate          = cells.item(Row,10).value().date();        //from date
                    PriceDiscAdmTrans.ToDate            = cells.item(Row,11).value().date();         //todate
                    PriceDiscAdmTrans.insert();
                    itemId=inventTable.ItemId;
       
                }
                 type = cells.item(row+1, 1).value().variantType();
        }
            ttsCommit;
        excel.quit();
        }
     
       main
        public static void main(Args _args)
        {
            VIK_SalesMaster_ExcelImport    VIK_SalesMaster_ExcelImport = new VIK_SalesMaster_ExcelImport();
       
       
             if(VIK_SalesMaster_ExcelImport.prompt())
                VIK_SalesMaster_ExcelImport.run();
        }
      

AX 2012 MAP X++ FOR EXISTING RECORDS MAP INSERT MAP CHECK MAP LOOKUP

AX 2012 MAP X++ FOR EXISTING RECORDS

MAP for Exist in excel upload
public void run()
{
    SysExcelApplication     excel;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    SysExcelCell            cell;

    SysExcelStyles          styles;
    SysExcelStyle           estyle;
    SysExcelFont            font;


    int                     row = 1;

    //vikas
    ProdTable               prodTable,prodTableRef,prodtabledate;
    InventDim               inventDim;
    int                     total1,total2,total3,total4,total5,total6;
    SysExcelWorksheetHelper worksheetHelper;
    SysExcelRange           range;
    ItemId                  itemId;
    InventOnhand            inventonHand;
    inventDim               inventDimRef;
    InventDimParm           inventDimParm;
    WrkCtrCapRes            WrkCtrCapRes1,WrkCtrCapRes2,WrkCtrCapRes3;
    WrkCtrTable             wrkCtrTable1,wrkCtrTable2,wrkCtrTable3;
    int                     x,y,z,j,k,l,fordays,mapi,mapint;
    WrkCtrIdBase            machine;
    SchedFromDate           mindate,mindateLess,mapdatefind,fordate;
    SchedToDate             maxdate1;
    date               strdate;
    str                 dateinstring;
    TransDate               transdate;

    Map                     map = new Map(Types::String,Types::Integer);
    Map                     mapintkey = new Map(Types::Integer,Types::String);

    InventTrans            inventTransTable;
   
    int                     days;

    str itemOrginStatus;


    excel = SysExcelApplication::construct();
    workbooks = excel.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();

    styles = workbook.styles();
    estyle  = styles.add("Header");
    font = estyle.font();
    font.bold(true);

    cell = cells.item(1, 1);
    cell.font().bold(true);
    cell.value('MONTH PRODUCTION PLANNING');
    //ITEM    PLAN    OPN STK    BAL TO BE PRODUCED    MTD    Operation    M/C

    cell = cells.item(3, 1);
    cell.value('SIZE');
    cell = cells.item(3, 2);
    cell.value('TYPE');
    cell = cells.item(3, 3);
    cell.value('PLAN');
    cell = cells.item(3, 4);
    cell.value('OPN STK');
    cell = cells.item(3, 5);
    cell.value('BAL TO BE PRODUCED');
    cell = cells.item(3, 6);
    cell.value('MTD    Operation');//NO OF
    cell = cells.item(3, 7);
    cell.value('M/C');
    row = 3;
    select maxof(SchedStart) from prodtabledate where prodtabledate.InventRefId == 'P000179';
    maxdate1 = prodtabledate.schedstart;
    prodtabledate.clear();
    select minof(SchedStart) from prodtabledate where prodtabledate.InventRefId == 'P000179';
    mindate = prodtabledate.schedstart;
    mindateLess = mindate -1;
     days = date2num(maxdate1) - date2num(mindate);
     fordays = days+10;
    for(j=10;j<fordays;j++)
    {
        map.insert(mindateLess+1,j);
        mindateLess = mindateLess+1;
    }
    //mapintkey
    for(mapi=10;mapi<fordays;mapi++)
    {
        mapintkey.insert(mapi,mindateLess+1);
        mindateLess = mindateLess+1;
    }
    //mapdate = 2015/9/23  ...9/28/2015
    for(k=10;k<fordays;k++)
    {
        cell = cells.item(3, k);
         if (Mapintkey.exists(k))
        {
            strdate = Mapintkey.lookup(k);
            dateinstring = Mapintkey.lookup(k);
        }
       // strdate = date2str(transdate,321,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits1or2,dateSeparator::Slash, DateYear::Digits4);
        cell.value(Mapintkey.lookup(dateinstring));

    }

    //map.insert('2', 'ew');
    //info(strFmt("%1",map.lookup(2)));

 while select prodTable join InventDim   where prodTable.ProdId == 'P000179' && prodTable.InventDimId == InventDim.inventDimId
   {
           // itemId = prodTable.ItemId;
             row= row+1;
             cell = cells.item(row, 1);
             cell.value(InventDim.InventSizeId);
             cell = cells.item(row, 2);
             cell.value(InventDim.InventColorId);
    while select prodTableRef join inventDimRef where prodTableRef.InventRefId == prodTable.ProdId
       {
            //row = row+1;
            cell = cells.item(row, 3); //plan
            cell.value(prodTableRef.qtysched);

            itemId = prodTable.ItemId;
            InventDimParm.initFromInventDim(inventDimRef);
            inventonHand = inventonHand::newParameters(itemId,inventDimRef,InventDimParm);
            cell = cells.item(row, 4); //
            cell.value(inventonHand.availPhysical());
            itemId = prodTable.ItemId;

            cell = cells.item(row, 5); //plan
            cell.value(prodTableRef.qtysched - inventonHand.availPhysical());
           //cell = cells.item(row, 6); //plan
            //cell.value(prodTableRef.qtysched - inventonHand.availPhysical());

            cell = cells.item(row, 7); //pool
            cell.value(prodTableRef.ProdPoolId);


            while select WrkCtrCapRes1 order by WrkCtrId,transdate where WrkCtrCapRes1.RefId == prodTableRef.ProdId && WrkCtrCapRes1.RefType == 1 //&& WrkCtrCapRes1.WrkCtrId == "BREHM-1"
           {   x = 8;y =10;//z=2;
               wrkCtrTable1.clear();
               select wrkCtrTable1 where wrkCtrTable1.Name == WrkCtrCapRes1.WrkCtrId;
               machine = WrkCtrCapRes1.WrkCtrId;
               cell = cells.item(row,8 ); //machine
               cell.value(machine);
                cell = cells.item(row, 9); //actual
                cell.value('Actual');
                row = row +1;
                cell = cells.item(row, 9); //plan
                cell.value('Plan');
                 if (Map.exists(WrkCtrCapRes1.TransDate))
                {
                    mapint = Map.lookup(WrkCtrCapRes1.TransDate);
                }
                cell = cells.item(row,mapint);
                cell.value(WrkCtrCapRes1.WrkCtrHours()*wrkCtrTable1.capacity);
            }


       }
   
        }


    worksheet.columns().autoFit();
    excel.visible(true);

}

Tuesday, 9 June 2015

SALES QUOTE UPDATION AX 2012 X++ CUSTOM WEB SERVICE

SALES QUOTE UPDATION AX 2012 
X++ CUSTOM WEB SERVICE
Sales Quote update
[AifCollectionTypeAttribute('return', Types::Container), SysEntryPointAttribute(true)]
public str updateQuote(QuotationIdBase _quoteId,CustCurrencyCode _currency, InventSiteName _site,ItemIdSmall _item,SalesQty _qty,comp_OrderType _orderType,comp_OrderCat _orderCategory,FormType_IN _saleTypeSalesTax,comp_SaleTypeExciseDuty   _saleTypeExcise,
                        String50 _domestic,String50 _export,String50 _e1Sale,string50 _price,TaxGroup _taxGroup,MarkupValue _freight)
{

    str                             log;
    str                             log_1,log_2,log_3,log_4,log_5,log_6,log_7,log_8,log_9;
    Inventsite                      site;
    InventLocation                  ware;
    SalesQuotationTable             quotation,quotationIdchk;
    SalesQuotationLine              line,line_2;
    InventDim                       dim;
    InventItemOrderSetupType        setupType   = InventItemOrderSetupType::Invent;
    InventTable                     inventTable;
    CustTable                       cust;
    InventDimCombination            comb;
    NoYes                           noyes;
    TmpTaxWorkTrans                 tmpTax;
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationTotals_Sales      salesQuotationTotals;
    TaxTable                        taxtable;
    str                             component;
    container                       con;
    int                             i ;
    compProductMasterDefault         prodMasterDef;
    MarkupTable                             markTab;
    MarkupTrans                             trans;

    select * from prodMasterDef;

   if(_orderCategory == 'Dealer-Customer')
            changeCompany(prodMasterDef.DealerCompany)
    {  // Validating from masters
         select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
     if(quotationIdchk.RecId && InventSite::exist(_site) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {

            ttsBegin;
            //updating header
            quotation.clear();
            select forupdate quotation where quotation.QuotationId ==  _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating line
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                               // && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
           trans.ModuleType  =  MarkupModuleType::Cust;
           trans.CurrencyCode = line.CurrencyCode;
           trans.MarkupCode    = markTab.MarkupCode;
           trans.Txt            = markTab.Txt;
           trans.MarkupCategory = MarkupCategory::Pcs;
           trans.Value = _Freight;
           Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
            while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
//             log_8 = num2str(abs(tmpTax.TaxAmount),0,2,1,1);
               log_8 =  num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
            //strFmt('Warehouse %1 is not valid for Sales Quote : %2',ware,_quoteId);
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
            if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);

        }

      }
      else
      {
           changeCompany(prodMasterDef.delCompany)
          {
       // validating masters
           select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
      if( quotationIdchk.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {
             ttsBegin;
            //creating header
            quotation.clear();
            select forUpdate quotation where quotation.QuotationId == _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.LanguageId = SystemParameters::getSystemLanguageId();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating lines
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                      //  && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                 line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();

             markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
               trans.ModuleType  =  MarkupModuleType::Cust;
               trans.CurrencyCode = line.CurrencyCode;
               trans.MarkupCode    = markTab.MarkupCode;
               trans.Txt            = markTab.Txt;
               trans.MarkupCategory = MarkupCategory::Pcs;
               trans.Value = _Freight;
               Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
              if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 for company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
             if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist for company %2',_quoteId,curext());
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);
        }
      }
    }

     info(strFmt("Sales Quote Update: %1 - %2 ",_quoteId,log));
     comp_RetailExceptionActivityLog::logEvent('Sales Quote Update',infolog.export());
     return log ;
    }

SALES QUOTE CREATION AX 2012 X++ CUSTOM WEB SERVICE

SALES QUOTE CREATION AX 2012 
X++ CUSTOM WEB SERVICE

[AifCollectionTypeAttribute('return', Types::String), SysEntryPointAttribute(true)]
public str CreateQuote(QuotationIdBase _quoteId,smmBusRelAccount _prospectId,CustAccount _customerId,LogisticsAddressing _billToAddress,LogisticsAddressing _shipToAddress,CustCurrencyCode _currency,
                        InventSiteName _site,InventLocationName _warehouse,ItemIdSmall _item,SalesQty _qty,comp_OrderType _orderType,comp_OrderCat _orderCategory,FormType_IN _saleTypeSalesTax,comp_SaleTypeExciseDuty   _saleTypeExcise,
                        String50 _domestic,String50 _export,String50 _e1Sale,string50 _price,TaxGroup _taxGroup,MarkupValue _freight)
{

    str                             log;
    str                             log_1,log_2,log_3,log_4,log_5,log_6,log_7,log_8,log_9;
    Inventsite                      site;
    InventLocation                  ware;
    SalesQuotationTable             quotation,quotationIdchk;
    SalesQuotationLine              line,line_2;
    InventDim                       dim;
    InventItemOrderSetupType        setupType   = InventItemOrderSetupType::Invent;
    InventTable                     inventTable;
    CustTable                       cust;
    InventDimCombination            comb;
    NoYes                           noyes;
    TmpTaxWorkTrans                 tmpTax;
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationTotals_Sales      salesQuotationTotals;
    TaxTable                        taxtable;
    str                             component;
    container                       con;
    int                             i,k ;
    // changes
    compProductMasterDefault         prodMasterDefault;
    MarkupTable                             markTab;
    MarkupTrans                             trans;

    select * from prodMasterDefault;

   if(_orderCategory == 'Dealer-Customer')
            changeCompany(prodMasterDefault.DealerCompany)
    {  // Validating from masters
        select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;

     if(!quotationIdchk.RecId &&InventSite::exist(_site) && InventLocation::exist(_warehouse) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)  &&  TaxGroupHeading::exist(_taxGroup))

        {

            ttsBegin;
            //creating header
            quotation.clear();
            quotation.initValue();
            quotation.CustAccount = _customerId;
            quotation.QuotationName = _customerId;
            quotation.InvoiceAccount = _customerId;
            quotation.initFromCustTable(true);
            quotation.QuotationId = _quoteId;
            quotation.BusRelAccount = _prospectId;
            quotation.QuotationStatus  = SalesQuotationStatus::Created;
            quotation.CurrencyCode = _currency;
            quotation.InventSiteId = _site;
            quotation.InventLocationId = _warehouse;
            quotation.ShippingDateRequested = systemDateGet();
            quotation.LanguageId = SystemParameters::getSystemLanguageId();
            quotation.comp_OrderType = _orderType;
            quotation.comp_OrderCat  = _orderCategory;
            quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
            quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
            quotation.comp_Domestic = str2enum(NoYes,_domestic);
            quotation.comp_Export = str2enum(NoYes,_export);
            quotation.insert();
            //creating line
            line.initValue();
            line.initFromSalesQuotationTable(quotation);
            line.initFromCustTable();
            inventTable = InventTable::find(_item);
            line.initFromInventTable(inventTable);
            line.ItemId = _item;
            //creating Inventory Dimensions
            dim.InventSiteId = _site;
            dim.InventLocationId  =_warehouse;
           // dim.configId = InventTable::find(line.ItemId).StandardConfigId;
            dim.configId = prodMasterDefault.DefaultConfig;
            dim = InventDim::findOrCreate(dim);
            dim.write();
            line.SalesQty = _qty;
            line.CurrencyCode = _currency;
            line.ShippingDateRequested = systemDateGet();
            line.InventDimId = dim.inventDimId;
            line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
            line.initFromSalesQuotationLine_IN(line);
            comb = InventDimCombination::findByInventDim(line.ItemId,dim);
            line.RetailVariantId = comb.RetailVariantId  ;
            line.ExciseTariffCodes_IN = Inventtable::find(_item).ExciseTariffCodes_IN;
            line.createLine(true,true,false,false,false,false,'',false);


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
            trans.clear();
            trans.initFromSalesQuotationLine(line);
            trans.initFromMarkupTable(marktab);
            trans.MarkupCategory = MarkupCategory::Pcs;
            trans.Value = _Freight;
            trans.LineNum = k;
            trans.insert();
            k++;

            //updating line Price
            select forUpdate line_2 where line_2.QuotationId == line.QuotationId
                        && line_2.ItemId == line.ItemId
                        && line_2.LineNum == line.LineNum;
            if(line_2.RecId)
            {
             line_2.SalesPrice = str2num(_price) - _freight;
             line_2.TaxGroup = _taxGroup;
            }
            line_2.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line_2.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');
            //info(strFmt('%1',log));
         }
        else
        {
            //InventSite::exist(_site) && InventLocation::exist(_warehouse)
            if(!InventSite::exist(_site))
            {
               log_1 = strFmt('Site %1 is not valid for Sales Quote - %2 for company %3',_site,_quoteId,curext());
            }
            if(!InventLocation::exist(_warehouse))
            {
                log_2 = strFmt('Warehouse %1 is not valid for Sales Quote - %2',_warehouse,_quoteId);
            }
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for Sales Quote - %2',_item,_quoteId);
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strfmt('SalesTax FormType %1 is not valid for Sales Quote - %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is not valid for Sales Quote - %2',_taxGroup,_quoteId);
            }
            if(quotationIdchk.RecId)
            {
                log_9 = strFmt('Sales Quote %1 already Exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_9);
        }

      }
      else
      {
           changeCompany(prodMasterDefault.delCompany)
          {
          select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;

       // validating masters
     // if(site.RecId && ware.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
     if(!quotationIdchk.RecId &&InventSite::exist(_site) && InventLocation::exist(_warehouse) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)  &&  TaxGroupHeading::exist(_taxGroup))

        {
             ttsBegin;
            //creating header
            quotation.clear();
            quotation.initValue();
            quotation.CustAccount = _customerId;
            quotation.QuotationName = _customerId;
            quotation.InvoiceAccount = _customerId;
            quotation.initFromCustTable(true);
            quotation.QuotationId = _quoteId;
            quotation.BusRelAccount = _prospectId;
            quotation.QuotationStatus  = SalesQuotationStatus::Created;
            quotation.CurrencyCode = _currency;
            quotation.InventSiteId = _site;
            quotation.InventLocationId = _warehouse;
            quotation.ShippingDateRequested = systemDateGet();
            quotation.LanguageId = SystemParameters::getSystemLanguageId();
            quotation.comp_OrderType = _orderType;
            quotation.comp_OrderCat  = _orderCategory;
            quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
            quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
            quotation.comp_Domestic = str2enum(NoYes,_domestic);
            quotation.comp_Export = str2enum(NoYes,_export);
            quotation.insert();
            //creating lines
            line.initValue();
            line.initFromSalesQuotationTable(quotation);
            line.initFromCustTable();
            inventTable = InventTable::find(_item);
            line.initFromInventTable(inventTable);
            line.ItemId = _item;
            //creating inventory dimension
            dim.InventSiteId = _site;
            dim.InventLocationId  =_warehouse;
            //dim.configId = InventTable::find(line.ItemId).StandardConfigId;
            dim.configId = prodMasterDefault.DefaultConfigdel;
            dim = InventDim::findOrCreate(dim);
            dim.write();
            line.SalesQty = _qty;
            line.CurrencyCode = _currency;
            line.ShippingDateRequested = systemDateGet();
            line.InventDimId = dim.inventDimId;
            line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
            line.initFromSalesQuotationLine_IN(line);
            comb = InventDimCombination::findByInventDim(line.ItemId,dim);
            line.RetailVariantId = comb.RetailVariantId  ;
            line.ExciseTariffCodes_IN = Inventtable::find(_item).ExciseTariffCodes_IN;
            line.createLine(true,true,false,false,false,false,'',false);


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
            trans.clear();
            trans.initFromSalesQuotationLine(line);
            trans.initFromMarkupTable(marktab);
            trans.MarkupCategory = MarkupCategory::Pcs;
            trans.Value = _Freight;
            trans.LineNum = k;
            trans.insert();
            K++;
            //updating price
             select forUpdate line_2 where line_2.QuotationId == line.QuotationId
                        && line_2.ItemId == line.ItemId
                        && line_2.LineNum == line.LineNum;
            if(line_2.RecId)
            {
             line_2.SalesPrice = str2num(_price)- _freight;
             line_2.TaxGroup = _taxGroup;

            }
            line_2.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line_2.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            log = con2StrUnlimited(con,'|');
            i =0 ;
            //log = con2Str(con,'');

         }
        else
        {
            if(!InventSite::exist(_site))
            {
               log_1 = strFmt('Site %1 is not valid for Sales Quote - %2 for company %3',_site,_quoteId,curext());
            }
            if(!InventLocation::exist(_warehouse))
            {
                log_2 = strFmt('Warehouse %1 is not valid for Sales Quote - %2',_warehouse,_quoteId);
            }
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for Sales Quote - %2',_item,_quoteId);
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strfmt('SalesTax FormType %1 is not valid for Sales Quote - %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is not valid for Sales Quote - %2',_taxGroup,_quoteId);
            }
             if(quotationIdchk.RecId)
            {
                log_9 = strFmt('Sales Quote %1 already Exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_9);

        }
          }
      }
   //  info(strFmt(" Sales Quote
     info(strFmt("Sales Quote for %1 is created - %2",_quoteId,log));
     comp_RetailExceptionActivityLog::logEvent('Sales Quote',infolog.export());
     return log ;
    }

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++  Introduction In our previous posts, we explored what Copilot can do o...