Form event execution sequence in Dynamics AX

0

This Blog will guide the sequence of event triggering while working on Form’s and Table in Dynamics AX.

Form Events

Table EventsTable Evnts2

 

Images from the Original blog of Afnan Zarif.

Advertisements

Emploee Lookup – Legal entity specific – Active Emploee

0

Sample Code to generate Employee Lookup . Which contains Active employee, Legal entity specific and here i have an extra filter to exclude workers starting from 00.

You can also use the same code to get the Terminated employee just by Slight change in the query .

public void lookup()
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
SysTableLookup sysTableLookup;

QueryBuildDataSource queryBuildDataSource1;
RecId _LegalEntity;
;

//Create an instance of SysTableLookup with the form control passed in
sysTableLookup = SysTableLookup::newParameters(tablenum(HcmWorker), this);

//Add the fields to be shown in the lookup form
sysTableLookup.addLookupfield(fieldnum(HcmWorker, PersonnelNumber), false);
sysTableLookup.addLookupMethod(‘Name’);

//create the query datasource
queryBuildDataSource = query.addDataSource(tablenum(HcmWorker));
queryBuildDataSource.addRange(fieldNum(HcmWorker, PersonnelNumber))
.value(SysQuery::valueLikeAfter(‘!00’));

queryBuildDataSource1 = queryBuildDataSource.addDataSource(tableNum(HcmEmployment));
queryBuildDataSource1.joinMode(JoinMode::ExistsJoin);
queryBuildDataSource1.relations(true);
queryBuildDataSource1.addRange(fieldNum(HcmEmployment, LegalEntity))
.value(SysQuery::value(CompanyInfo::findDataArea(SelectableDataArea.valueStr()).recId));

//add the query to the lookup form
sysTableLookup.parmQuery(query);

// Perform lookup
sysTableLookup.performFormLookup();

}

Run RDP based report from Code & passing parameter using Data contract

0

Bsic Code to run RDP based report using x++ and passing parameters to data contract.

SrsReportRunController controller = new SrsReportRunController();
VendSOAReportTmpContract rdpContract = new VendSOAReportTmpContract ();
SRSPrintDestinationSettings settings;

 

controller.parmReportName(ssrsReportStr(VendSOATmpReport,PrecisionDesign));

controller.parmShowDialog(false);
rdpContract.parmVendAccount(VendPurchOrderJour.OrderAccount);
controller.parmReportContract().parmRdpContract(rdpContract);
controller.startOperation();

Step name of Workflow

0

Below is the reference sample code to get the workflow step name.

public display str 25 stepName(PurchReqTable _purchReqTable)
{
container con;
PurchReqTable purchReqTable;
PurchReqTableHistory purchReqTableHistory;
WorkflowTrackingStatusTable workflowTrackingStatus;
WorkflowTrackingTable workflowTracking;
utcdatetime validDate = DateTimeUtil::utcNow();
WorkflowStepName stepName;
TransDate stepSinceDate;
PurchReqRequisitionStatus status;
TransDate statusSinceDate;
RefRecId workflowTrackingStatusRecId;
RefRecId workflowStepRecId;
UserInfo userInfo;
WorkflowTrackingTable workflowTrackingLocal,workflowTrackingLocal2,workflowTrackingLocal3;
WorkflowStepTable workflowstepTable;
RefRecId _purchReqTableRecId = _purchReqTable.RecId;

/* Get the current status */
select firstonly validTimeState(validDate)
CreatedDateTime, RequisitionStatus from purchReqTable
where purchReqTable.RecId == _purchReqTableRecId

outer join CreatedDateTime from purchReqTableHistory
where purchReqTableHistory.PurchReqTable == purchReqTable.RecId

outer join RecId from workflowTrackingStatus
order by workflowTrackingStatus.CreatedDateTime desc
where workflowTrackingStatus.ContextTableId == purchReqTable.TableId &&
workflowTrackingStatus.ContextRecId == purchReqTable.RecId;

/* line-item subworkflow */
select firstonly RecId, Name, CreatedDateTime, TrackingContext, TrackingType,WorkflowElementTable,WorkflowTrackingStatusTable,WorkflowStepTable from workflowTracking
order by workflowTracking.CreatedDateTime desc
where workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId;
if (workflowTracking.TrackingContext != WorkflowTrackingContext::LineItemElement ||
workflowTracking.TrackingType != WorkflowTrackingType::Creation)
{
/* Current step */
select firstonly RecId, Name, CreatedDateTime, TrackingContext, TrackingType,WorkflowElementTable,WorkflowTrackingStatusTable,WorkflowStepTable from workflowTracking
order by workflowTracking.CreatedDateTime desc
where workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId &&
workflowTracking.TrackingContext == WorkflowTrackingContext::Step &&
workflowTracking.TrackingType == WorkflowTrackingType::Creation;
}

if (purchReqTable != null)
{
status = purchReqTable.RequisitionStatus;
userInfo = xUserInfo::find(false, curUserId());

if (purchReqTableHistory != null)
{
statusSinceDate = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(purchReqTableHistory.CreatedDateTime, userInfo.PreferredTimeZone));
}
else
{
statusSinceDate = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(purchReqTable.CreatedDateTime, userInfo.PreferredTimeZone));
}

if (workflowTracking != null)
{
stepName = workflowTracking.Name;
stepSinceDate = DateTimeUtil::date(workflowTracking.CreatedDateTime);
workflowTrackingStatusRecId = workflowTrackingStatus.RecId;
workflowStepRecId = workflowTracking.WorkflowStepTable;
}
select firstOnly workflowTrackingLocal
where workflowTrackingLocal.TrackingType == WorkflowTrackingType::Return &&
workflowTrackingLocal.WorkflowElementTable == workflowTracking.WorkflowElementTable &&

workflowTrackingLocal.WorkflowTrackingStatusTable == workflowTracking.WorkflowTrackingStatusTable &&
workflowTrackingLocal.RecId > workflowTracking.RecId;

if (workflowTrackingLocal)
{
select firstOnly workflowTrackingLocal2
where workflowTrackingLocal2.TrackingType == WorkflowTrackingType::Creation &&
workflowTrackingLocal2.TrackingContext == WorkflowTrackingContext::Step &&
workflowTrackingLocal2.WorkflowElementTable == workflowTrackingLocal.WorkflowElementTable &&
workflowTrackingLocal2.WorkflowStepTable == workflowTracking.WorkflowStepTable &&
workflowTrackingLocal2.WorkflowTrackingStatusTable == workflowTrackingLocal.WorkflowTrackingStatusTable &&
workflowTrackingLocal2.RecId > workflowTrackingLocal.RecId;
}
if (!workflowTrackingLocal2)
{

 

select firstOnly workflowTrackingLocal2
where workflowTrackingLocal2.TrackingType == WorkflowTrackingType::Creation &&
workflowTrackingLocal2.TrackingContext == WorkflowTrackingContext::Task &&
workflowTrackingLocal2.WorkflowElementTable == workflowTrackingLocal.WorkflowElementTable &&
workflowTrackingLocal2.WorkflowStepTable == workflowTracking.WorkflowStepTable &&
workflowTrackingLocal2.WorkflowTrackingStatusTable == workflowTrackingLocal.WorkflowTrackingStatusTable &&
workflowTrackingLocal2.RecId > workflowTrackingLocal.RecId;

}

if (workflowTrackingLocal2 != null)
{

workflowstepTable = workflowstepTable::findRecId(workflowTrackingLocal2.WorkflowStepTable);
stepName = workflowstepTable.Name;
stepSinceDate = DateTimeUtil::date(workflowTrackingLocal2.CreatedDateTime);
workflowTrackingStatusRecId = workflowTrackingLocal2.WorkflowTrackingStatusTable;
workflowStepRecId = workflowTrackingLocal2.WorkflowStepTable;
}

}

return stepName;
}

Replace \ Delegate Workflow User

0

With this piece of Code we can delegate Workflow from One User to another Using X++

Here I am taking example of Purchase Requistion


static void waj_replaceWorkflowUser(Args _args)
{
workflowtrackingstatustable workflowtrackingstatustable;
workflowtrackingtable workflowtrackingtable;
PurchReqTable purchreqTable;
WorkflowWorkItemTable workItem;
WorkflowStepTable workFlowStepTableSequence, workFlowStepTable;
WORKFLOWTRACKINGCOMMENTTABLE WORKFLOWTRACKINGCOMMENTTABLE;
purchreqTable = purchreqTable::findPurchReqId('PR-010454');
select workItem order by RecId desc
where workItem.RefTableId == tableNum(purchReqTable) &&
workItem.RefRecId == purchreqtable.recid &&
workItem.Status != WorkFlowWorkItemStatus::Completed &&
workItem.UserId == 's.Wajahat'; // slect user to replace
{
info(strFmt('%1', workItem.RefRecId));
}

WorkflowWorkItemActionManager::dispatchWorkItemAction(workItem,’Delegated’,’Ali’,WorkflowWorkItemActionType::Delegate,’PurchReqDelegate’,false);
}