cancel
Showing results for 
Search instead for 
Did you mean: 

normal approval process after BADIforApprovalCustomResponsibilityDetermination

former_member606838
Participant
0 Kudos

Hi Experts,

I have developed a code to add the managers of the employees/cost center managers as approvers of project baseline if they have planned hours in a project. I achieved that using the BADI: BADIforApprovalCustomResponsibilityDetermination

But when the project have no employees or non of the employees have any hours the the baseline approval will be pending with no approvers and will need to be assigned an approver manually from the Business Task management. Is there anyway to skip the custom approval process if the conditions didn't met?

My code is as follow:

/*
Add your SAP Business ByDesign scripting language implementation for:
Enhancement Option: BADIforApprovalCustomResponsibilityDetermination
Operation: DETERMINE_RESPONSIBILE_EMP
Script file signature
----------------------------
Parameter: InputData of type BADIforApprovalCustomResponsibilityDetermination
Returns: CustomApprovalCategoryEmployeeResponsibles
Note: 
  - To use code completion, press CTRL+J.
*/
import AP.FO.Task.Global;
import AP.Common.GDT;
import AP.ProjectManagement.Global;
import ABSL;
var result : CustomApprovalCategoryEmployeeResponsibles;
var baselineUUID : DataType::UUID;
//Get the baseline
baselineUUID.content = Library::UUID.ParseFromString(InputData.KeyFieldValue.content.ToString());
var baseline : ProjectBaseline=ProjectBaseline.Retrieve(baselineUUID);
var projectID = baseline.BaseProjectID;
//Get the prject associated with this baseline
var QueryProject = Project.QueryByCreationIdentity;
var SelectionParams = QueryProject.CreateSelectionParams();
SelectionParams.Add(QueryProject.ProjectID.content, "I", "EQ", projectID.content);
var projects = QueryProject.Execute(SelectionParams);
if (projects.Count() != 0)
{
var project = projects.GetFirst();
var participants = project.Participant;
foreach (var p in participants)
{

var lt : CustomApprovalCategoryEmployeeResponsibles.EmployeeResponsibles;
var zeroWorkingHours : Quantity;
zeroWorkingHours.content = 0;
zeroWorkingHours.unitCode = p.TotalPlannedWorkQuantity.unitCode;
var manager : DataType::UUID;
// If the employee has planned working hours, then the cost center manager needs to be an approver.
if (p.TotalPlannedWorkQuantity.GreaterThan(zeroWorkingHours))
{
//Get the current cost center manager.
if (p.Employee.IsSet())
{//check for direct manager.
if (p.Employee.Position.CurrentResponsibleManager.GetFirst().IsSet())
{
if (p.Employee.Position.CurrentResponsibleManager.GetFirst().ResponsibleManagingEmployee.IsSet())
{
if (!p.Employee.Position.CurrentResponsibleManager.GetFirst().ResponsibleManagingEmployee.UUID.IsInitial())
{
manager = p.Employee.Position.CurrentResponsibleManager.GetFirst().ResponsibleManagingEmployee.UUID;
}
}
}
//check for the higher cost center manager
else if (p.Employee.Position.CurrentSuperordinateCostCentre.GetFirst().IsSet())
{
if (p.Employee.Position.CurrentSuperordinateCostCentre.GetFirst().ResponsibleManager.GetFirst().IsSet())
{
if (!p.Employee.Position.CurrentSuperordinateCostCentre.GetFirst().ResponsibleManager.GetFirst().ResponsibleManagingEmployeeUUID.IsInitial())
{
manager = p.Employee.Position.CurrentSuperordinateCostCentre.GetFirst().ResponsibleManager.GetFirst().ResponsibleManagingEmployeeUUID;
}
}

}
//if manager found add the manger to the approvers.
if (!manager.IsInitial())
{
lt.content = manager.content;
result.EmployeeResponsibles.Add(lt);
}
} 
}
}
}
return result;

So what if result didn't have any thing?

Thanks,

Mousa

View Entire Topic
Reinaud
Explorer
0 Kudos

Can't you just let the approval revert back to the project manager? So:

if(manager.IsInitial()){

*logic to set project manager as approver*

}

former_member606838
Participant
0 Kudos

That's it! Let me try that for now. I just cannot create a patch for some reason. Let me see what is happening here.