Skip to Content

A Null exception every time I try to create a custom BO instance from a standard BO.

Hi!

I created one custom BO called ProjectbaselineCostCenters that has a [0,n] node called Studiengange which is translation of cost centers in German. I wrote this logic in ProjectBaseline BO extension in the BeforeSave event.

import ABSL;
import AP.Common.GDT as apCommonGDT;
import AP.FO.MOM.Global;
import AP.ProjectManagement.Global;
var ProjectbaselineCostCenter = ProjectbaselineCostCenters.Retrieve(this.UUID);
if (!ProjectbaselineCostCenter.IsSet())
{
//Baseline

var pbData : elementsof ProjectbaselineCostCenters;
var pbccData : elementsof ProjectbaselineCostCenters.Studiengange;
var pbccsData : collectionof elementsof ProjectbaselineCostCenters.Studiengange;
//Project
var query = Project.QueryByCreationIdentity;
var para = query.CreateSelectionParams();
para.Add(query.ProjectID.content, "I", "EQ", this.BaseProjectID.content);
var project = query.Execute(para);
if (project.Count() > 0)
{
var ProjectCostCentersInstance = ProjectCostCenters.Retrieve(project.GetFirst().UUID);
foreach (var cc in ProjectCostCentersInstance.Studiengange)
{
pbccData.Studiengang = cc.Studiengang;
pbccData.StudiengangsID = cc.StudiengangsID;
pbccsData.Add(pbccData);
}
pbData.BaseProjectID = this.BaseProjectID;
pbData.ProjectbaselineUUID = this.UUID;
ProjectbaselineCostCenter = ProjectbaselineCostCenters.Create(pbData);
if (ProjectbaselineCostCenter.Studiengange.Count() < 1)
{

ProjectbaselineCostCenter.Studiengange.CreateMass(pbccsData); //Dump here!!!!!!

}
}
}<br>

I want to create a ProjectbaselineCostCenters object at every time I create the project baseline. I wrote the above logic but I have null exception at like 57 which is the last line of code. What is wrong in there?

Thanks,

Mousa

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Jul 23, 2020 at 04:03 PM

    Mousa,

    You have the below code snippet. You're not checking whether ProjectbaselineCostCenter is set after you call the .Create() --- so my guess is that 'if (ProjectbaselineCostCenter.Studiengange.Count() < 1)' is the line that's crashing, because it's trying to access the Studiengange node of an object that may not exist.

    var ProjectbaselineCostCenter = ProjectbaselineCostCenters.Retrieve(this.UUID);
    if (!ProjectbaselineCostCenter.IsSet())
    {
    ...
    ProjectbaselineCostCenter = ProjectbaselineCostCenters.Create(pbData);
    if (ProjectbaselineCostCenter.Studiengange.Count() < 1)
    {
    ProjectbaselineCostCenter.Studiengange.CreateMass(pbccsData); //Dump here!!!!!!
    }
    }
    
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.