Skip to Content

“Project Management” object is exposed as a Service Type Object from SAP Business One Version 9.2 PL03. It is yet to be implemented in DTW.

Here is how to use the Project Management object using DI API:

1. Add a Project using DI API:

int absEntryOfCreatedProject = -1;
SAPbobsCOM.CompanyService oCompServ = null;
SAPbobsCOM.ProjectManagementService pmgService = null;

try
{

    oCompServ = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
    pmgService = (SAPbobsCOM.ProjectManagementService)oCompServ.GetBusinessService(SAPbobsCOM.ServiceTypes.ProjectManagementService);
    SAPbobsCOM.PM_ProjectDocumentData project = (SAPbobsCOM.PM_ProjectDocumentData)pmgService.GetDataInterface(SAPbobsCOM.ProjectManagementServiceDataInterfaces.pmsPM_ProjectDocumentData);
    project.ProjectName = "ProjectByDI_01";
    project.Owner = 1;
    project.StartDate = new DateTime(2016, 2, 1);
    project.DueDate = new DateTime(2016, 11, 30);
    project.ClosingDate = new DateTime(2016, 12, 31);
    project.ProjectType = SAPbobsCOM.ProjectTypeEnum.pt_External;
    project.BusinessPartner = "C20000";
    project.ContactPerson = 2;
    project.Territory = 1;
    project.SalesEmployee = 5;
    project.AllowSubprojects = SAPbobsCOM.BoYesNoEnum.tYES;
    project.ProjectStatus = SAPbobsCOM.ProjectStatusTypeEnum.pst_Started;
    project.FinancialProject = "PRJ01";
    project.RiskLevel = SAPbobsCOM.RiskLevelTypeEnum.rlt_High;
    project.Industry = 1;
    project.Reason = "Test comment";
    project.AttachmentEntry = 1;
    SAPbobsCOM.PM_ProjectDocumentParams projectParam = pmgService.AddProject(project);
    absEntryOfCreatedProject = projectParam.AbsEntry;

}

catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

finally
{
    if (pmgService != null)
    {
        MessageBox.Show(absEntryOfCreatedProject.ToString());
        System.Runtime.InteropServices.Marshal.ReleaseComObject(pmgService);
    }
}

2. Update a Project by adding ‘Documents’ to ‘Stages’ using DI API:

SAPbobsCOM.CompanyService oCompServ = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
SAPbobsCOM.ProjectManagementService pmgService = (SAPbobsCOM.ProjectManagementService)oCompServ.GetBusinessService(SAPbobsCOM.ServiceTypes.ProjectManagementService);
SAPbobsCOM.PM_ProjectDocumentParams projectToUpdateParam = pmgService.GetDataInterface(SAPbobsCOM.ProjectManagementServiceDataInterfaces.pmsPM_ProjectDocumentParams);

try
{
    projectToUpdateParam.AbsEntry = 1;
    SAPbobsCOM.PM_ProjectDocumentData project = pmgService.GetProject(projectToUpdateParam);
    SAPbobsCOM.PM_StagesCollection stagesCollection = project.PM_StagesCollection;
    SAPbobsCOM.PM_StageData stage = stagesCollection.Add();
    stage.StageType = 1;
    stage.StartDate = DateTime.Now;
    stage.CloseDate = stage.StartDate.AddDays(30);
    stage.Task = 1;
    stage.Description = "StageWithDocByDI_01";
    stage.ExpectedCosts = 150;
    stage.PercentualCompletness = 7;
    stage.IsFinished = SAPbobsCOM.BoYesNoEnum.tNO;
    stage.StageOwner = 5;
    stage.AttachmentEntry = 1;
    stage = stagesCollection.Add();
    stage.StageType = 2;
    stage.StartDate = DateTime.Now.AddMonths(1);
    stage.CloseDate = stage.StartDate.AddDays(30);
    stage.Task = 2;
    stage.Description = "StageWithDocByDI_02";
    stage.ExpectedCosts = 250;
    stage.PercentualCompletness = 8;
    stage.IsFinished = SAPbobsCOM.BoYesNoEnum.tNO;
    stage.StageOwner = 5;
    stage.DependsOnStage1 = 1;
    stage.StageDependency1Type = SAPbobsCOM.StageDepTypeEnum.sdt_Project;
    stage.DependsOnStageID1 = 1;

    SAPbobsCOM.PM_DocumentsCollection documentsCollection = project.PM_DocumentsCollection;
    SAPbobsCOM.PM_DocumentData document = documentsCollection.Add();
    document.StageID = 1;
    document.DocType = SAPbobsCOM.PMDocumentTypeEnum.pmdt_APCreditMemo;
    document.DocEntry = 7;
    pmgService.UpdateProject(project);
    MessageBox.Show("OK");
}

catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

finally
{
    if (pmgService != null)
    {
        System.Runtime.InteropServices.Marshal.ReleaseComObject(pmgService);
    }
}

3. Cancelling a Project using DI API:

SAPbobsCOM.CompanyService oCompServ = null;
SAPbobsCOM.ProjectManagementService pmgService = null;

try
{
    oCompServ = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
    pmgService = (SAPbobsCOM.ProjectManagementService)oCompServ.GetBusinessService(ServiceTypes.ProjectManagementService);
    SAPbobsCOM.PM_ProjectDocumentParams projectToCancelParam = pmgService.GetDataInterface(ProjectManagementServiceDataInterfaces.pmsPM_ProjectDocumentParams);
    projectToCancelParam.AbsEntry = 1;
    pmgService.CancelProject(projectToCancelParam);
}
catch (Exception ex)
{
    throw new Exception(string.Format("Call PMG failed with error code: {0}", ex.Message));
}
finally
{
    if (pmgService != null)
    {
        System.Runtime.InteropServices.Marshal.ReleaseComObject(pmgService);
    }
}

4. Adding a SubProject using DI API:

try
{
    CompanyService oCompServ = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
    ProjectManagementService phaService = (SAPbobsCOM.ProjectManagementService)oCompServ.GetBusinessService(ServiceTypes.ProjectManagementService);
    PM_SubprojectDocumentData subProject = phaService.GetDataInterface(ProjectManagementServiceDataInterfaces.pmsPM_SubprojectDocumentData);
    subProject.Owner = 4;
    subProject.SubprojectName = "SubProjectNameByDI_01_01";
    subProject.StartDate = new DateTime(2016, 5, 1);
    subProject.DueDate = new DateTime(2016, 5, 15);
    subProject.SubprojectEndDate = new DateTime(2016, 5, 31);
    subProject.ProjectID = 1;
    subProject.SubprojectType = 1;
    subProject.SubprojectContribution = 15;
    subProject.SubprojectStatus = SubprojectStatusTypeEnum.sst_Open;
    subProject.ActualCost = 50;
    subProject.PlannedCost = 200;
    SAPbobsCOM.PM_SubprojectDocumentParams subprojectParam = phaService.AddSubproject(subProject);
}
catch (Exception ex)
{
    throw new Exception(string.Format("Call failed with error code: {0}", ex.Message));
}
finally
{
    if (pmgService != null)
    {
        System.Runtime.InteropServices.Marshal.ReleaseComObject(pmgService);
    }
}

Update: UDFs have been implemented for “PM_ProjectDocumentData”, “PM_StageData”, “PM_SubprojectDocumentData” since SAP Business One Version 9.3 PL01 .

To report this post you need to login first.

12 Comments

You must be Logged on to comment or reply to a post.

    1. ANKIT CHAUHAN Post author

      Hi Former Member,

      Currently, I do not find any possibility to do this. I will inform you about it as early as possible.

      Kind regards,

      ANKIT CHAUHAN

      SAP SME Support

      (0) 
    2. ANKIT CHAUHAN Post author

      Hi Former Member,

      Currently, UDFs are not implemented for PM_ProjectDocumentData or PM_SubprojectDocumentData

       

      Kind regards,

      ANKIT CHAUHAN

      SAP SME Support

       

      (1) 
  1. Former Member

    Hi ANKIT CHAUHAN,
    Can you help give me demo adding Project management with DI API. I dont know how to use DI API with Project Management
    Thanks.

    (0) 
    1. ANKIT CHAUHAN Post author

      Hi,

      Sorry for the late reply!

      To use the above mentioned program, you need to perform the following:

      1. Create a company connection using DI API. For this, if you need a help, you need to install SAP Business One SDK and find the sample codes at the following location:C:\Program Files (x86)\SAP\SAP Business One SDK\Samples
      2. Once the company connection is successful, you can use the above mentioned program as it is and notice what is being done by DI API. This can be observed from SAP Business One Client itself.

      Hope it helps!

      Kind regards,

      ANKIT CHAUHAN

      SAP SME Support

      (1) 
  2. Tulio Enterlein

    Hi Ankit!

    Firstly, thanks for your post and samples about Project Management. However, I have doubt about how to implement UDF in this code.

    After installing SAP 9.3 PL5, I’m trying to integrate Project Management basead on your sample and update UDF, but an error is shown on my application:

    Invalid Field Name

    The line which is occuring the error:

    project.UserFields.Item("U_ValorProj").Value = 5.0;

    The field “U_ValorProj” was created correcly in Project Management as Numeric (16.9), but I have no idea how to fix it.

    Besides that, I changed the field name to “ValorProj” but the error persists:

    project.UserFields.Item("ValorProj").Value = 5.0;

    Could you help me?

    Best Regards

    Tulio

     

    (0) 

Leave a Reply