Wednesday, 24 September 2014

How to Import XML file Through X++ coding , SalesOrder XML file How to Import using X++ code

static void SalesOrderCreatandInvoice(Args _args)
{
    RetailTransactionService    RetailTransactionService;
    str   dc;

    XmlDocument doc;
    XmlNodeList data;
    XmlElement nodeTable;
    XmlElement nodeAccount;
    XmlElement nodeName;
    #define.filename(@'C:\Temp\CreateCustomerOrder.xml')
    doc = XmlDocument::newFile(#filename);
    doc.load(@'C:\Temp\CreateCustomerOrder.xml');
   // dc = any2str(doc.lo);

    RetailTransactionService::createCustomerOrder(doc.toString());
}



XML file:

Customer Order / SalesOrder file .

<CustomerOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <AutoPickOrder>false</AutoPickOrder>
  <TransactionId>0000000296</TransactionId>
  <OrderType>SalesOrder</OrderType>
  <Status>0</Status>
  <DocumentStatus>0</DocumentStatus>
  <CustomerAccount>2002</CustomerAccount>
  <AddressRecord>22565427550</AddressRecord>
  <InventLocationId>BOSTON</InventLocationId>
  <StoreId>BOSTON</StoreId>
  <TerminalId>BOSTON-1</TerminalId>
  <TotalManualDiscountAmount>0</TotalManualDiscountAmount>
  <TotalManualDiscountPercentage>0</TotalManualDiscountPercentage>
  <ExpiryDate>2014-09-10</ExpiryDate>
  <HourOfDay>16</HourOfDay>
  <DeliveryMode>60</DeliveryMode>
  <RequestedDeliveryDate>2014-08-11</RequestedDeliveryDate>
  <Comment />
  <PrepaymentAmountOverridden>false</PrepaymentAmountOverridden>
  <PrepaymentAmountApplied>95.61</PrepaymentAmountApplied>
  <PreviouslyInvoicedAmount>0</PreviouslyInvoicedAmount>
  <SalespersonStaffId>000137</SalespersonStaffId>
  <CurrencyCode>USD</CurrencyCode>
  <LoyaltyCardId />
  <HasLoyaltyPayment>false</HasLoyaltyPayment>
  <ChannelReferenceId>STONON-1300001</ChannelReferenceId>
  <Email>marykay@contoso.com</Email>
  <Items>
    <Item ItemId="0061" RecId="0" Quantity="1" QuantityPicked="0" Unit="ea" Price="24.9900000000000000" Discount="0" DiscountPercent="0" NetAmount="24.99" Comment="" TaxGroup="MA" TaxItemGroup="RP" SalesMarkup="0" Status="0" InventLocationId="BOSTON" DeliveryMode="60" RequestedDeliveryDate="2014-08-11" AddressRecord="22565427550" BatchId="" SerialId="" VariantId="" LineDscAmount="0" PeriodicDiscount="0" PeriodicPercentageDiscount="0" LineManualDiscountAmount="0" LineManualDiscountPercentage="0" TotalDiscount="0" TotalPctDiscount="0" IgnDeliveryTime="00:00:00">
      <Charges />
      <Discounts />
      <Salespersons>
        <Salesperson SalespersonId="000100" SalespersonName="Josh Edwards" />
        <Salesperson SalespersonId="000155" SalespersonName="Renata Krausova" />
      </Salespersons>
    </Item>
    <Item ItemId="0066" RecId="0" Quantity="1" QuantityPicked="0" Unit="ea" Price="74.9900000000000000" Discount="0" DiscountPercent="0" NetAmount="74.99" Comment="" TaxGroup="MA" TaxItemGroup="RP" SalesMarkup="0" Status="0" InventLocationId="BOSTON" DeliveryMode="60" RequestedDeliveryDate="2014-08-11" AddressRecord="22565427550" BatchId="" SerialId="" VariantId="" LineDscAmount="0" PeriodicDiscount="0" PeriodicPercentageDiscount="0" LineManualDiscountAmount="0" LineManualDiscountPercentage="0" TotalDiscount="0" TotalPctDiscount="0" IgnDeliveryTime="00:00:00">
      <Charges />
      <Discounts />
      <Salespersons>
        <Salesperson SalespersonId="000110" SalespersonName="Dan Park" />
        <Salesperson SalespersonId="000111" SalespersonName="Patrick Elliot" />
        <Salesperson SalespersonId="000120" SalespersonName="Andrew Lan" />
        <Salesperson SalespersonId="000137" SalespersonName="Emma Harris" />
      </Salespersons>
    </Item>
  </Items>
  <Charges />
  <Payments>
    <Payment PaymentType="1" Amount="10.62" Currency="" Prepayment="false" />
  </Payments>
  <Affiliations />
</CustomerOrder>

Thursday, 18 September 2014

getting buf2Buf by using x++ coding

This method takes two table buffers (from and To) as the parameter and copies the value from the Form Table Buffer to the To Table Buffer.

static void buf2BufByName(Common  _from, Common  _to)
{
    DictTable   dictTableFrom   = new DictTable(_from.TableId);
    DictTable   dictTableTo     = new DictTable(_to.TableId);
    DictField   dictFieldFrom;
    FieldId     fieldIdFrom     = dictTableFrom.fieldNext(0);
    FieldId     fieldIdTo
    ;

    while (fieldIdFrom && ! isSysId(fieldIdFrom))
    {
        dictFieldFrom   = new DictField(_from.TableId, fieldIdFrom);
        if(dictFieldFrom)
        {
            fieldIdTo = dictTableTo.fieldName2Id(dictFieldFrom.name());
           // info(dictFieldFrom.name());

            if(fieldIdTo)
                _to.(fieldIdTo) = _from.(fieldIdFrom);
        }
        fieldIdFrom = dictTableFrom.fieldNext(fieldIdFrom);
    }
}
 

Thursday, 11 September 2014

Lookup method in Ax 2012 R3 using X++ code


Custom lookup method in ax 2012 R3 using X++ code

client server public static void lookup(FormControl  _formControl)
{
 SysTableLookup sysTableLookup;
 Query   query;
 QueryBuildDataSource qbd;
 RetailStoreTable  retailStoreTable;
 RetailChannelTable  retailChannelTable;
 TmpLegalentitywisestore TmpLegalentitywisestore;
 OMOperatingUnit   OMOperatingUnit;


  // This collection will store the records that must be inserted into the database
 RecordInsertList CurrCompanyToBeInserted = new RecordInsertList(tableNum(TmpLegalentitywisestore));
 delete_from TmpLegalentitywisestore;

while select retailChannelTable where retailChannelTable.inventLocationDataAreaId == curext()
join retailStoreTable where retailStoreTable.RecId == retailChannelTable.RecId
join OMOperatingUnit where OMOperatingUnit.RecId == retailChannelTable.OMOperatingUnitID
 {
 TmpLegalentitywisestore.StoreID = retailStoreTable.StoreNumber;
 TmpLegalentitywisestore.Name = OMOperatingUnit.Name;
 CurrCompanyToBeInserted.add(TmpLegalentitywisestore); // it to the RecordInsertList array
}

 CurrCompanyToBeInserted.insertDatabase(); // read to execute the insert operation
 sysTableLookup = SysTableLookup::newParameters(tablenum(TmpLegalentitywisestore), _formcontrol);
 query = new Query();
 qbd = query.addDataSource(tablenum(TmpLegalentitywisestore));
// add the fields to the lookup list
 sysTableLookup.addLookupfield(fieldnum(TmpLegalentitywisestore,storeid));
 sysTableLookup.addLookupfield(fieldnum(TmpLegalentitywisestore,Name));
 sysTableLookup.parmQuery(query);
 sysTableLookup.performFormLookup();

 }

call this method on form data source.>> field >>Lookup method
public void lookup(FormControl _formControl, str _filterStr)
{
     IgnTmpLegalentitywisestore::lookup(_formControl);
}




 
 
 

Tuesday, 9 September 2014

Default finance dimensions In Ax 2012 R3 using X++ code

How to create Default finance dimensions  in Ax 2012 R3 using x++ code

create a new field on your table like table name Invent location
fieldType : Int64
Name : STBDefaultDimension

//On form
create new tab like named :TabSTBFinancialDimensions

class declaration

DimensionDefaultingController dimensionDefaultingController; // <pvk>
init method
 // <pvk>
    dimensionDefaultingController = DimensionDefaultingController::constructInTabWithValues(true, true, true, 0, this, TabSTBFinancialDimensions, "@SYS138487");
    dimensionDefaultingController.parmAttributeValueSetDataSource(inventLocation_ds, fieldStr(InventLOcation, STBDefaultDimension));
 // </PVK>
add methods on form>>datasource level
public void delete()
{
    super();
    dimensionDefaultingController.deleted();
}
public void write()
{
  
    dimensionDefaultingController.writing(); // <pvk>
    super();
}

public int active()
{
    int ret;
    ret = super();
    dimensionDefaultingController.activated(); // <pvk>
    return ret;
}

public void pageActivated()
{
    dimensionDefaultingController.pageActivated();
    super();
}