Hi Girish,
I found the below piece of code. Can you tell me where should I add the above code.
internal final class MassTimeApproval
{
public static void actionItem(WorkflowWorkItemActionType action, WorkflowWorkItemTable _workitem, WorkflowComment _comment,MenuItemName _menuItem )
{
WorkflowWorkItemActionManager::dispatchWorkItemAction(_workitem,
_comment,
'',
action,
_menuItem,
'');
}
public static WorkflowWorkitemTable getActiveWorkitemForRecord(Common _buffer)
{
WorkflowWorkitemTable workitem;
RecId refRecid = _buffer.RecId;
TableId refTableId = _buffer.TableId;
select workitem where workitem.RefRecId == refRecid && workitem.RefTableId == refTableId
&& (workitem.Status == WorkflowWorkItemStatus::Pending || workitem.Status == WorkflowWorkItemStatus::Delegated);
return workitem;
}
public static container getMenuItemForType(WorkflowWorkItemtable _workitem, WorkflowWorkItemActionType _type, UserId user)
{
#Workflow
WorkflowElementTable workflowElement;
SysDictWorkflowElement dictWorkflowElem;
WorkflowConfigOutcome workflowConfigOutcome;
WorkflowWorkItemActionType workItemActionType;
Map actionList;
MapEnumerator actionListEnum;
Map outcomeList;
MapEnumerator outcomeListEnum;
SysDictMenu sysDictMenu;
MenuItemName mi;
//WorkflowWorkItemActionDelegate WorkflowWorkItemActionDelegate;
container ret = ["",""];
;
if (_workitem.Type != WorkflowWorkItemType::Recall)
{
workflowElement = WorkflowElementTable::find(_workitem.ElementId);
if (workflowElement.RecId != 0)
{
dictWorkflowElem = new SysDictWorkflowElement(workflowElement.ElementType, workflowElement.ElementName);
if (_workitem.Type == WorkflowWorkItemType::RequestChange || _workitem.Type == WorkflowWorkItemType::Return)
{
//ADD RESUBMIT ITEMS
mi = dictWorkflowElem.resubmitMenuItem();
sysDictMenu = SysDictMenu::newMenuItem(mi,MenuItemType::Action);
if (_type == WorkflowWorkItemActionType::Resubmit)
{
ret = [mi, sysDictMenu.label()];
return ret;
}
}
else
{
workflowConfigOutcome = workflowElement.getElementOutcomes();
actionList = workflowConfigOutcome.parmActionList();
actionListEnum = actionList.getEnumerator();
outcomeList = workflowConfigOutcome.parmOutcomList();
outcomeListEnum = outcomeList.getEnumerator();
while (outcomeListEnum.moveNext())
{
if (outcomeListEnum.currentValue() == NoYes::Yes)
{
mi = dictWorkflowElem.actionMenuItem(outcomeListEnum.currentKey());
sysDictMenu = SysDictMenu::newMenuItem(mi,MenuItemType::Action);
workItemActionType = WorkflowWorkItemActionManager::findActionTypeForMenuItem(_workitem, mi);
if (workItemActionType == _type)
{
if (sysDictMenu)
{
ret = [mi, sysDictMenu.label()];
break;
}
}
}
}
if (_type == WorkflowWorkItemActionType::Delegate)
{
while (actionListEnum.moveNext())
{
// make sure action is enabled
if (actionListEnum.currentValue() == NoYes::Yes)
{
if (actionListEnum.currentKey() == #WorkflowWorkItemActionDelegate)
{
// allow delegate if work item is not a final approver work item
if (_workitem.Type != WorkflowWorkItemType::FinalApprover)
{
mi = dictWorkflowElem.delegateMenuItem();
sysDictMenu = SysDictMenu::newMenuItem(mi,MenuItemType::Action);
ret = [mi, sysDictMenu.label()];
}
}
}
}
}
}
}
}
return ret;
}
public static void main(Args args)
{
FormDataSource ds = args.record().dataSource();
Common record;
WorkflowWorkItemTable workitem;
WorkflowComment comment;
MenuItemName menuitem;
str label;
WorkflowWorkItemActionType action;
boolean commented;
WorkflowWorkItemActionDialog dialog;
TSTimesheetTable tsTimesheetTable;
action = WorkflowWorkItemActionType::Complete;
for(record = ds.getFirst(true) ? ds.getFirst(true) : ds.cursor(); record; record = ds.getNext())
{
workitem = MassTimeApproval::getActiveWorkitemForRecord(record);
if (workitem)
{
[menuitem,Label] = MassTimeApproval::getMenuItemForType(workitem, action , curUserId());
if (!commented)
{
dialog = WorkflowWorkItemActionDialog::construct(workitem, action, new MenuFunction(menuitem, MenuItemType::Action));
dialog.run();
if (dialog.parmIsClosedOK())
{
commented = true;
comment = dialog.parmWorkflowComment();
}
else
{
break;
}
}
if (menuitem)
{
MassTimeApproval::actionItem(action, workitem,comment,menuitem);
tsTimesheetTable = TSTimesheetTable::findRecId(record.RecId);
if(tsTimesheetTable)
{
SourceDocumentProcessorFacade::submitSourceDocumentImplementation(tsTimesheetTable, false, SourceDocumentAccountingStatus::Completed);
}
}
else
{
error(strFmt("No %1 action defined for item %2", action, record.caption()));
}
}
}
ds.research();
ds.refresh();
}
}
Thanks,
Priya