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

Batch job D365

Hi,

Contact:

[DataContractAttribute,
SysOperationContractProcessingAttribute(classStr(CounterEntryOutliersUIBuilderClass))]
public class CounterEntryOutliersContract
{
Transdate startDate,endDate;
MROObjectCounterID objectCounterID;
MROObjectID objectId;

[DataMemberAttribute(‘Counter’),
SysOperationDisplayOrderAttribute(‘1’)]
public MROObjectCounterID parmCounter(MROObjectCounterID _objectCounterID = objectCounterID)
{
objectCounterID = _objectCounterID;
return objectCounterID;
}

[DataMemberAttribute(‘objectId’),
SysOperationDisplayOrderAttribute(‘2’)]
public MROObjectID parmObjectId(MROObjectID _objectId = objectId)
{
objectId = _objectId;
return objectId;
}

[DataMemberAttribute(‘StartDate’),
SysOperationDisplayOrderAttribute(‘3’)]
public StartDate parmStartDate(TransDate _startDate = startDate)
{
startDate = _startDate;
return startDate;
}

[DataMemberAttribute(‘EndDate’),
SysOperationDisplayOrderAttribute(‘4’)]
public EndDate parmEndDate(TransDate _endDate = endDate)
{
endDate = _endDate;
return endDate;
}

DP:

[
SRSReportQueryAttribute(queryStr(ObjectCounterQuery)),
SRSReportParameterAttribute(classStr(CounterEntryOutliersContract))
]
public class
CounterEntryOutliersDP extends SRSReportDataProviderBase
{

[SysEntryPointAttribute(false)]
public void processReport()
{
M

query = this.parmQuery();

contract = this.parmDataContract();

counterID = contract.parmCounter();
objectId = contract.parmObjectId();
startdate = contract.parmStartDate();
endDate = contract.parmEndDate();

startDateTime = DateTimeUtil::newDateTime(startdate,0);
endDateTime = DateTimeUtil::newDateTime(endDate,86400);

delete_from objectCounterTmp;
if(counterID)
{
select firstonly parmObjectCounter where parmObjectCounter.CounterID == counterID;
query.dataSourceTable(tablenum(ObjectCounter)).addRange(fieldnum(ObjectCounter,Counter)).value(queryValue(parmObjectCounter.RecId));
}
if(objectId)
{
select RecId from objectTable where objectTable.ObjectID == objectId;
query.dataSourceTable(tablenum(ObjectCounter)).addRange(fieldnum(ObjectCounter,Object)).value(queryValue(objectTable.RecId));// 5637178326));
}

query.dataSourceTable(tablenum(ObjectCounter)).addRange(fieldnum(ObjectCounter,CounterDateTime)).value(queryRange(startDateTime, endDateTime));

queryRun = new QueryRun(query);

ttsbegin;
while (queryRun.next())
{
this.insertTmpTable(mroObjectCounter);
}
ttsCommit;
}

private void insertTmpTable(MROObjectCounter objectCounter)
{
objectCounterTmp.insert();
}

[SRSReportDataSetAttribute(“ObjectCounterTmp”)] //tmp table
Public OObjectCounterTmp getObjectCounterTmp()
{
select * from objectCounterTmp;

return objectCounterTmp;
}

UIBuilder : 

class CounterEntryOutliersUIBuilderClass extends SysOperationAutomaticUIBuilder
{
CounterEntryOutliersContract contract;

DialogField dialogCounter;
DialogField dialogStartDate;
DialogField dialogEndDate;
DialogField dialogObjectId;

public void build()
{
Dialog dialogLocal = this.dialog();
contract = this.dataContractObject();
this.addDialogField(methodStr(CounterEntryOutliersContract,parmCounter), contract);
this.addDialogField(methodStr(CounterEntryOutliersContract,parmStartDate), contract);
this.addDialogField(methodStr(CounterEntryOutliersContract,parmEndDate), contract);
}

public void getFromDialog()
{
contract = this.dataContractObject();
super();
}

public void initializeFields()
{
contract = this.dataContractObject();
}

public void lookupCounter(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(ParmObjectCounter), _control);
;
sysTableLookup.addLookupfield(fieldnum(ParmObjectCounter, CounterID),true);

queryBuildDataSource = query.addDataSource(tablenum(ParmObjectCounter));

sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();
}

public void postBuild()
{
;
super();
dialogCounter = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(CounterEntryOutliersContract,parmCounter));

dialogCounter.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(CounterEntryOutliersUIBuilderClass,lookupCounter),this);

dialogStartDate = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(CounterEntryOutliersContract,parmStartDate));
dialogEndDate = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(CounterEntryOutliersContract,parmEndDate));

}

public void postRun()
{
Dialog dialogLocal = this.dialog();
super();
// This method should be called in order to handle events on dialogs.
dialogLocal.dialogForm().formRun().controlMethodOverload(false);
}

}

 

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);

COC for Close method on Form

HI, From Update12, its possible to write COC for forms as well!

[ExtensionOf(formStr(StageUpdate))]
final class StageUpdate_Extension
{
public void closeOk()
{

next closeOk();
Formrun thisForm = @this;
FormRun callerForm = thisForm.args().caller();

if( callerForm.name() == formstr(WorkOrderTable))

{

FormDataSource woLineDS = callerForm.dataSource(formDataSourceStr(WorkOrderTable,WorkOrderLine ));
WorkOrderLine selectedWOLine = woLineDs.cursor();

}

}

lookupReference & lookup on Form

public Common lookupReference(FormReferenceControl _formReferenceControl)
{
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tablenum(ParmJobVariant), _formReferenceControl, true);
Query query;
QueryBuildDataSource qbdsJobVariant;
QueryBuildDataSource qbdsJobTypeVariant;
QueryBuildRange queryBuildRange;

sysTableLookup.addLookupfield(fieldnum(ParmJobVariant, JobVariantId));
sysTableLookup.addLookupfield(fieldnum(ParmJobVariant, Description));

query = new Query();
qbdsJobVariant = query.addDataSource(tablenum(ParmJobVariant));
qbdsJobTypeVariant = qbdsJobVariant.addDataSource(tableNum(ParmJobTypeVariant));
qbdsJobTypeVariant.relations(true);
qbdsJobTypeVariant.joinMode(JoinMode::ExistsJoin);

queryBuildRange = qbdsJobTypeVariant.addRange(fieldnum(ParmJobTypeVariant, JobType));
queryBuildRange.value(SysQuery::value(workOrderLine.JobType));

sysTableLookup.parmQuery(query);
return sysTableLookup.performFormLookup();
}

 

public void lookup()
{
MROObjectRecID objectrecid;
sysTableLookup sysTableLookup = sysTableLookup::newParameters(tablenum(ParmObjectCounter), this);
Query query;
QueryBuildDataSource qbds;
QueryBuildRange queryBuildRange;

objectrecid = WorkOrderLine.Object;

query = new Query();
qbds = query.addDataSource(tablenum(ParmObjectCounter));
qbds = qbds.addDataSource(tableNum(ObjectCounter));
qbds.joinMode(JoinMode::ExistsJoin);
qbds.relations(true);

qbds.addRange(fieldNum(ObjectCounter,Object)).value(queryValue(objectrecid));

qbds.addSortField(fieldNum(ParmObjectCounter, CounterID));
qbds.addSortField(fieldnum(ParmObjectCounter, Name));
qbds.addSortField(fieldnum(ParmObjectCounter, SequenceNumber));
qbds.orderMode(OrderMode::GroupBy);

sysTableLookup.addLookupfield(fieldnum(ParmObjectCounter, CounterID));
sysTableLookup.addLookupfield(fieldnum(ParmObjectCounter, Name));
sysTableLookup.addLookupfield(fieldnum(ParmObjectCounter, SequenceNumber));

sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

Lookup by cancel super:

[FormControlEventHandler(formControlStr(WorkOrderTable, WorkOrderLine_JobTypeCopy1), FormControlEventType::Lookup)]
public static void WorkOrderLine_JobTypeCopy1_OnLookup(FormControl sender, FormControlEventArgs e)
{

FormRun             formRun          = sender.formRun();

WorkOrderTable workOrderTable = sender.formRun().dataSource(FormDataSourceStr(WorkOrderTable, workordertable)).cursor() as WorkOrderTable;

//canceling super()
FormControlCancelableSuperEventArgs cancelableArgs = e as FormControlCancelableSuperEventArgs;
cancelableArgs.CancelSuperCall();

FormReferenceGroupControl ObjectId = formRun.design(0).controlName(“WorkOrderLine_Object”);

SysReferenceTableLookup lookup = SysReferenceTableLookup::newParameters(tableNum(ParmJobType), sender);
Query query = new Query();
QueryBuildDataSource qbdsJobType = query.addDataSource(tableNum(ParmJobType));
qbdsJobType.addRange(fieldNum(MROParmJobType, Task)).value(SysQuery::valueNot(enum2str(MROTask::Blank)));
lookup.addLookupfield(fieldNum(MROParmJobType, JobTypeID));
lookup.addLookupfield(fieldNum(MROParmJobType, Name));

lookup.parmQuery(query);

lookup.performFormLookup();
}

Event handlers on Form

HI, get current record based on event handler class

[FormDataSourceEventHandler(formDataSourceStr(WorkOrderTable, WorkOrderTable), FormDataSourceEventType::Initialized)]
public static void WorkOrderTable_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{

FormRun             formRun          = sender.formRun();
FormDataSource      WorkOrderTable_ds   = formRun.dataSource(formDataSourceStr(WorkOrderTable, WorkOrderTable)) as FormDataSource;
WorkOrderTable WorkOrderTable= WorkOrderTable_ds.cursor();

}

 

Form Control :

FormFunctionButtonControl buttonWorkOrderTableCreate = formRun.design(0).controlName(“WorkOrderTableCreate”);

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