最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

D365: 如何在 X++ 中获取工作流受让人/D365: How to get workflow assignee in X++

网络文摘 William 734浏览 0评论

Purpose:

Demonstrate how can we get the user, the workflow is assigned to, for purchase orders in X++.

Application:

Dynamics 365 for Finance and Operations

    Business requirement:

    Get the user, the workflow is assigned to, for purchase orders.

    Solution:

    We can use the code below to get the user, the workflow is assigned to, for purchase orders. The following code is an event handler for Inserted event on table WorkflowWorkItemTable. The code takes the assignee User Id and saves it in the extension table.

    Code

    /// <summary>
    /// Defaults assignee to purchase order extension table.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(WorkflowWorkItemTable), DataEventType::Inserted)]
    public static void WorkflowWorkItemTable_onInserted(Common sender, DataEventArgs e)
    {
    	WorkflowWorkItemTable workflowWorkItemTable;
    	ATLAS_PurchTableExtended purchTableExtended;
    	PurchTable purchTable;
    
    	workflowWorkItemTable = sender as WorkflowWorkItemTable;
    
    	if (workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem)
    	{
    		if (workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending)
    		{
    			if (workflowWorkItemTable.RefTableId == tableNum(PurchTable))
    			{
    				if (workflowWorkItemTable.CompanyId)
    				{
    					changecompany(workflowWorkItemTable.CompanyId)
    					{
    						purchTable = PurchTable::findRecId(workflowWorkItemTable.RefRecId, true);
    						purchTableExtended = ATLAS_PurchTableExtended::find(purchTable.RecId, true);
    
    						if (purchTableExtended)
    						{
    							try
    							{
    								ttsbegin;
    								purchTableExtended.PurchAssignee = workflowWorkItemTable.UserId;
    								purchTableExtended.update();
    								ttscommit;
    							}
    							catch (Exception::Error)
    							{
    								error(strFmt("@ATLAS:ErrorWhileDefaultingAssignee"));
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    }
    
    发表我的评论
    取消评论

    表情

    Hi,您需要填写昵称和邮箱!

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址