Category: Ax 2012

creating Purchase order Packing slip through X++

{

PurchFormLetter             purchFormLetter;

PurchFormletterParmData     purchFormLetterParmData;

PurchParmUpdate             purchParmUpdate;

PurchParmTable              purchParmTable;

PurchParmLine               purchParmLine;

PurchTable                  purchTable;

PurchLine                   purchLine;

PurchId                     purchId;

Num                         packingSlipId;

 

purchId         = “00001625”;

packingSlipId   = “00001625”;

purchTable      = PurchTable::find(purchId);

 

ttsBegin;

// Create PurchParamUpdate table

purchFormLetterParmData = PurchFormletterParmData::newData(

DocumentStatus::PackingSlip,

VersioningUpdateType::Initial);

 

purchFormLetterParmData.parmOnlyCreateParmUpdate(true);

purchFormLetterParmData.createData(false);

purchParmUpdate = purchFormLetterParmData.parmParmUpdate();

 

// Set PurchParmTable table

purchParmTable.clear();

purchParmTable.TransDate                = SystemDateGet();

purchParmTable.Ordering                 = DocumentStatus::PackingSlip;

purchParmTable.ParmJobStatus            = ParmJobStatus::Waiting;

purchParmTable.Num                      = packingSlipId;

purchParmTable.PurchId                  = purchTable.PurchId;

purchParmTable.PurchName                = purchTable.PurchName;

purchParmTable.DeliveryName             = purchTable.DeliveryName;

purchParmTable.DeliveryPostalAddress    = purchTable.DeliveryPostalAddress;

purchParmTable.OrderAccount             = purchTable.OrderAccount;

purchParmTable.CurrencyCode             = purchTable.CurrencyCode;

purchParmTable.InvoiceAccount           = purchTable.InvoiceAccount;

purchParmTable.ParmId                   = purchParmUpdate.ParmId;

purchParmTable.insert();

 

// Set PurchParmLine table

while select purchLine

where purchLine.PurchId == purchTable.purchId

{

purchParmLine.InitFromPurchLine(purchLine);

 

purchParmLine.ReceiveNow    = PurchLine.PurchReceivedNow;

purchParmLine.ParmId        = purchParmTable.ParmId;

purchParmLine.TableRefId    = purchParmTable.TableRefId;

purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);

purchParmLine.setLineAmount();

purchParmLine.insert();

}

 

purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);

purchFormLetter.transDate(systemDateGet());

purchFormLetter.proforma(false);

purchFormLetter.specQty(PurchUpdate::ReceiveNow);

purchFormLetter.purchTable(purchTable);

 

purchFormLetter.parmParmTableNum(purchParmTable.ParmId);

purchFormLetter.parmId(purchParmTable.ParmId);

purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());

purchFormLetter.run();

ttsCommit;

}

Advertisements

Posting Product receipt for PO

Hi, Below sample code used to post product receipt for specific PO.

purchTable = PurchTable::find(‘PO0012555’);
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchformLetter.getLast();
purchFormLetter.transDate(transDate);
numberSeq  = NumberSeq::newGetNum(PurchParameters::numRefPurchPackingSlipId()).num();
purchFormLetter.update(purchTable,
“14”,// numberSeq, //this is coming out blank
transDate,
PurchUpDate::All,
AccountOrder::None,
false,
false);

Number seq in D365

HI,

  1. Create new EDT
  2. Add EDT to new table and write below method at table level.
    1. static NumberSequenceReference numRefMROBulkTransferNumber()
      {
      return NumberSeqReference::findReference(extendedTypeNum(MROBulkTransferNumber));
      }
  3. write new class to extend existing module class
    1. [ExtensionOf(classStr(NumberSeqModuleMRO))]
      final class NumberSeqModuleMRO_Extension
      {protected void loadModule()
      {
      NumberSeqDatatype datatype = NumberSeqDatatype::construct();

      next loadModule(); // Execute the augmented original class method

      datatype.parmDatatypeId(extendedtypenum(MROBulkTransferNumber));
      datatype.parmReferenceHelp(literalstr(“Number for Bulk transfer”));
      datatype.parmWizardIsManual(NoYes::No);
      datatype.parmWizardIsChangeDownAllowed(NoYes::No);
      datatype.parmWizardIsChangeUpAllowed(NoYes::No);
      datatype.parmWizardLowest(1);
      datatype.parmWizardHighest(99999999);
      datatype.parmSortField(82);
      datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
      this.create(datatype);
      }}

      2.[ExtensionOf(classStr(NumberSeqModuleMRO))]
      final class NumberSeqModuleMRO_Extension
      {

      protected void loadModule()
      {
      NumberSeqDatatype datatype = NumberSeqDatatype::construct();

      next loadModule(); // Execute the augmented original class method

      datatype.parmDatatypeId(extendedtypenum(MROBulkTransferNumber));
      datatype.parmReferenceHelp(literalstr(“Number for Bulk transfer”));
      datatype.parmWizardIsManual(NoYes::No);
      datatype.parmWizardIsChangeDownAllowed(NoYes::No);
      datatype.parmWizardIsChangeUpAllowed(NoYes::No);
      datatype.parmWizardLowest(1);
      datatype.parmWizardHighest(99999999);
      datatype.parmSortField(82);
      datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
      this.create(datatype);
      }

      }

  4. Create new Runnable class(Job)
    1. class RunnableClass_numberSeq
      {
      /// <summary>
      /// Runs the class with the specified arguments.
      /// </summary>
      /// <param name = “_args”>The specified arguments.</param>
      public static void main(Args _args)
      {NumberSeqModuleMRO numberSeqMod = new NumberSeqModuleMRO();
      numberSeqMod.load();
      }

      }

  5. To go Organization Administration -> CommonForms -> Numbersequences -> Numbersequences -> Generate -> run the wizard.
  6. Navigate to module(MRO in my case): Setup -> Project management parameters form -> Num Seq.  You will find your new numberSeq

Merging two queries ranges

HI Below sample code used to merge 2 queries ranges.

private void merge(Query _queryPRA, Query _this)
{
QueryBuildDataSource rpa, pfr;
int rpaRanges,i, rpaFilters;
QueryBuildRange range;
QueryFilter queryFilter;

//Fetch ranges from Query
rpaRanges =_queryPRA.dataSourceTable(tableNum(SalesTable)).rangeCount();
for (i=1 ; i<=rpaRanges; i++)
{
range = _queryPRA.dataSourceTable(tableNum(SalesTable)).range(i);

_this.dataSourceTable(tablenum(SalesTable)).addRange(_queryPRA.dataSourceTable(tableNum(SalesTable)).range(i).field()).value(queryValue(range.value()));
}

//fetch user filters from Dialog
rpaFilters = _queryPRA.queryFilterCount();

for (i=1 ; i<=rpaFilters; i++)
{
queryFilter = _queryPRA.queryFilter(i);

_this.dataSourceTable(tablenum(SalesTable)).addRange(fieldName2id(tableNum(SalesTable), _queryPRA.queryFilter(i).field())).value(queryValue(queryFilter.value()));
}
}

SQL in X++, range in where clause

Below case is when ‘AccessFeedsFilter’ has value it should fetch that reocrds only if its empty: it should fetch all

 

while select SKUNumber, ItemId, inventDimId,LifeCycleStatusFlag,ItemName, InboundDepth, InboundHeight, InboundWeight, InboundWidth,
OutboundDepth, OutboundHeight, OutboundWeight, OutboundWidth, ActualDepth, ActualHeight, ActualWeight, ActualWidth, RetailVariantId, Description, BasePrice
from productsAndVariants
where (productsAndVariants.LifeCycleStatusFlag == ogoParameters.AccessFeedsFilter && ogoParameters.AccessFeedsFilter != “”) || (ogoParameters.AccessFeedsFilter == “” && true)

 

 

************* compare 2 fields. if not same only get data ***********

qbr = SysQuery::findOrCreateRange(this.parmQuery().dataSourceTable(tablenum(DRF_VendTransVendInvoiceJourView)),

fieldnum(DRF_VendTransVendInvoiceJourView,CostLedgerVoucher),fieldnum(DRF_VendTransVendInvoiceJourView,Voucher));

qbr.value(strFmt(‘(%1 != %2)’,

fieldStr(DRF_VendTransVendInvoiceJourView, CostLedgerVoucher),

fieldStr(DRF_VendTransVendInvoiceJourView, Voucher)));

Split text multiple lines in Email body

HI, Below smaple code used to show splited text in email body.

{

SysMailer mailer;
SysEmailParameters parameters;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
OWIStoreTable OWIStoreTable;
Notes bodymsg, bodymsghtml;
ListIterator iterator;
List strlist=new List(Types::String);
;
permission.assert();
mailer = new SysMailer();
parameters = SysEmailParameters::find();

if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}

mailer.fromAddress(‘test@AX.com’);
mailer.tos().appendAddress(‘AAA@gmail.com’);
mailer.subject(‘System Test’);

strlist =strSplit(‘AAA  BBB’,”\n”);

iterator = new ListIterator(strlist);

while(iterator.more())
{
bodymsg += strFmt(“%1<br>”,iterator.value());
iterator.next();
}

bodymsg = strReplace(bodymsg,’\n’,'<br>’);
bodymsg =bodymsg + “\n” + strFmt(“Last order %2 received for this webtore on: %1”, _lastSalesOrder.createdDateTime);

bodymsghtml= strFmtLB(bodymsg);

mailer.htmlBody(bodymsghtml);

mailer.sendMail();
}

Email sending using file template

HI, below sample code used to send email using Email tempalte formate in multiple lines and header formate.

static void sendMail(Email _defEmail, SysEmailId _emailTemplate, PurchTable PurchTable)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject;
Notes msgbody ;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;

SysEmailTable table;
SysEmailMessageTable message;

str newMessageBody;

;

if(_defEmail)
{
if (parameters.SMTPRelayServerName)
relayServer = parameters.SMTPRelayServerName;
else
relayServer = parameters.SMTPServerIPAddress;

portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();

table = SysEmailTable::find(_emailTemplate);
message = SysEmailMessageTable::find(table.EmailId, table.DefaultLanguage);
if (message)
{
newMessageBody = VendorSendEmail::renderLetter(message,PurchTable);
}
subject = message.Subject;
msgbody = newMessageBody;

CodeAccessPermission::revertAssert();

try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
mailer.fromAddress(SysUserInfo::find().Email);
mailer.tos().appendAddress(_defEmail);
mailer.subject(subject);
mailer.htmlBody(msgbody);
mailer.sendMail();
CodeAccessPermission::revertAssert();
info(“@CIT957”);
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();

while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
info (“error”);
}
}
else
error(“done”);

}