Replace \ Delegate Workflow User

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

Advertisements

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 Ledger dimension from string values

1 – By using the below code one can create ledger dimesion recId using X++
Combination of Main Account and DimensionValue

container offsetAccount;

RefRecId ledgerDimension;

offsetAccount = [‘11850000’, ‘11850000’, 3, ‘Department’, ‘101’, ‘Customer’,‘Cus-101’, ‘Vendor’, ‘Vend-101’];
//[MainAccount,MainAccount, NoOfDimensions, DimensionName, value]

ledgerDimension = AxdDimensionUtil::getLedgerAccountId(offsetAccount);

2 – Create Ledger dimension from main account (default account) and default dimension

The DimensionDefaultingService::serviceCreateLedgerDimension() method can be used to create ledger dimension from main account and default dimension.

JournalTrans.LedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(_defaultAccount,
JournalTrans.DefaultDimension);