Sales order workflow participant in D365fo x++
Sales order workflow participant in D365fo x++
/// <summary
/// Sales order workflow participant
/// </summary>
public class AZAQ_OrderManagerParticipantProvider implements WorkflowParticipantProvider
{
/// <summary>
/// Gets the participant token name displayed in workflow config.
/// </summary>
/// <returns>WorkflowParticipantTokenList object.</returns>
public WorkflowParticipantTokenList getParticipantTokens()
{
// Constructs the new user group list.
WorkflowParticipantTokenList userGroups = WorkflowParticipantTokenList::construct();
userGroups.add("Sales Order Rep", "Sales Order Rep person");
userGroups.add("Sales Rep2", "Sales Order Rep 2 person");
userGroups.add("Support Rep1", "Sales order support Rep 1 person");
return userGroups;
}
/// <summary>
/// Resolve method
/// </summary>
/// <param name = "_context">_context</param>
/// <param name = "_participantTokenName">_participantTokenName</param>
/// <returns>WorkflowUserList</returns>
public WorkflowUserList resolve(WorkflowContext _context, WorkflowParticipantToken _participantTokenName)
{
WorkflowUserList workflowUserList = WorkflowUserList::construct();
DirPersonUser personUser;
OMTeam team;
DirPartyRelationship partyRelationship;
DirRelationshipTypeTable relationshipTypeTable;
// Verify if participant token is set
if (!_participantTokenName)
{
throw error("@SYS105453");
}
switch (_participantTokenName)
{
case "Sales Order Rep" :
workflowUserList = this.salesResponsibleWorker(_context);
break;
case "Sales Rep2" :
workflowUserList = this.salesRep2Worker(_context);
break;
case "Support Rep1" :
workflowUserList = this.salesSupport1Worker(_context);
break;
default:
}
return workflowUserList;
}
/// <summary>
/// This method gets the sales responsible worker from the sales order customer account.
/// </summary>
/// <param name = "_context">WorkflowContext class</param>
/// <returns>WorkflowUserList</returns>
public WorkflowUserList salesResponsibleWorker(WorkflowContext _context)
{
WorkflowUserList workflowUserList = WorkflowUserList::construct();
HcmWorker worker;
SalesTable salesTable;
CustTable custTable;
if (_context.parmTableId() == tableNum(SalesTable))
{
select RecId, CustAccount, WorkerSalesResponsible from salesTable
where salesTable.RecId == _context.parmRecId();
//custTable = CustTable::find(salesTable.CustAccount);
}
if(salesTable.WorkerSalesResponsible == 0)
{
throw error("Sales responsible person is not attached to the sales order");
}
else
{
HcmWorker hcmWorker = HcmWorker::find(salesTable.WorkerSalesResponsible);
DirPartyTable dirPartyTable;
DirPersonUser personUser = HcmWorker::findPersonUser(hcmWorker.RecId);
workflowUserList.add(personUser.User);
}
return workflowUserList;
}
public WorkflowUserList salesRep2Worker(WorkflowContext _context)
{
WorkflowUserList workflowUserList = WorkflowUserList::construct();
HcmWorker worker;
SalesTable salesTable;
CustTable custTable;
if (_context.parmTableId() == tableNum(SalesTable))
{
select RecId, CustAccount, DSAWorkerSalesResponsible2 from salesTable
where salesTable.RecId == _context.parmRecId();
//custTable = CustTable::find(salesTable.CustAccount);
}
if(salesTable.DSAWorkerSalesResponsible2 == 0)
{
throw error("Sales responsible 2 person is not attached to the sales order");
}
else
{
HcmWorker hcmWorker = HcmWorker::find(salesTable.DSAWorkerSalesResponsible2);
DirPartyTable dirPartyTable;
DirPersonUser personUser = HcmWorker::findPersonUser(hcmWorker.RecId);
workflowUserList.add(personUser.User);
}
return workflowUserList;
}
public WorkflowUserList salesSupport1Worker(WorkflowContext _context)
{
WorkflowUserList workflowUserList = WorkflowUserList::construct();
HcmWorker worker;
SalesTable salesTable;
CustTable custTable;
if (_context.parmTableId() == tableNum(SalesTable))
{
select RecId, CustAccount, WorkerSalesTaker from salesTable
where salesTable.RecId == _context.parmRecId();
//custTable = CustTable::find(salesTable.CustAccount);
}
if(salesTable.WorkerSalesTaker == 0)
{
throw error("Sales support 1 person is not attached to the sales order");
}
else
{
HcmWorker hcmWorker = HcmWorker::find(salesTable.WorkerSalesTaker);
DirPartyTable dirPartyTable;
DirPersonUser personUser = HcmWorker::findPersonUser(hcmWorker.RecId);
workflowUserList.add(personUser.User);
}
return workflowUserList;
}
}
Comments
Post a Comment