Form event execution sequence in Dynamics AX

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

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

}

Step name of Workflow

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

Enable Modified by and Created by on ALL Parameters tables

Handy Code to have , Can be use to change any of the property of a table also just with the slightest change.

 

static void Waj_EnableProperties(Args _args)

{

SysDictTable dictTable,sysDictTable;
TreeNode node;
#AOT Name name;
TreeNode treeNode;
str indexName;
#Properties
;

treeNode = TreeNode::findNode(#TablesPath);
treeNode = treeNode.AOTfirstChild();

while (treeNode)

{
name = treeNode.AOTname();
sysDictTable = SysDictTable::newTableId(treeNode.applObjectId());

if ((sysDictTable.tableGroup() == tableGroup::Parameter ||
sysDictTable.tableGroup() == tableGroup::Group) &&
!sysDictTable.isMap() &&
!sysDictTable.isTmp() &&
!sysDictTable.isView() &&
sysDictTable.enabled())
{

node = SysDictTable.treeNode();
node.AOTsetProperty(#PropertyCreatedBy, #PropertyValueYes);

node.AOTsetProperty(#PropertyCreatedDateTime, #PropertyValueYes);
node.AOTsetProperty(#PropertyModifiedBy, #PropertyValueYes);
node.AOTsetProperty(#PropertyModifiedDateTime, #PropertyValueYes);

node.AOTsave();

node.treeNodeRelease();
node = null;

}

}

}

Create Default dimension using x++

The following job will get a DimensionAttributeValueSet record ID base on the a set of dimension values.

 

static void CreateDefaultDimensions(Args _args)
{
PurchTable purchTable;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;

int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;

// Note that “Item” is not one of the default dimension,
// but DimensionAttributeValueSetStorage will handle it gracefully
container conAttr = [“Project”, “Vendor”]; // Dimensions
container conValue = [“1001”, “Ven-0046”]; //  respective Values
str dimValue;

purchTable = purchTable::find(‘000471’);

for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

if (dimensionAttribute.RecId == 0)
{
continue;
}

dimValue = conPeek(conValue,i);

if (dimValue != “”)
{
// The last parameter is “true”. A dimensionAttributeValue record will be created if not found.
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
}

result = valueSetStorage.save();
purchTable.selectForUpdate(true);
ttsBegin;
purchTable.DefaultDimension = result;
purchTable.doUpdate();
ttsCommit;
}

Process Industries Add-On for Microsoft Dynamics AX 2009

Recently  I got a requirement to install PI 2009 on one of my client. What I figured is the sequence of installation is very important

Here are the steps to follow:

1. Install AX2009 RTM (SYS layer)
2. Install SP1 (SYP layer)
3. Install GLS layer if needed
4. Install Process Industries 5.1.3.1 (BUS layer (compatible with existing GLS))
5. Install RU7 (SYP (+ GLP layer))
6. Install PI BUP layer (specific to localization)
7. Open AX client and run Installation Checklist

 

BUP layers Installation file Download link is here

 

Hope this will save Some on time 🙂