cancel
Showing results for 
Search instead for 
Did you mean: 

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

former_member606838
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member183363
Active Contributor
0 Kudos

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!!!!!!
}
}
former_member606838
Participant
0 Kudos

I don't know how that was possible but yes it was the issue. But how! I am already using:

ProjectbaselineCostCenter = ProjectbaselineCostCenters.Create(pbData);



So I thought that no need to check after that!
former_member183363
Active Contributor
0 Kudos

Mousa,

The creation isn't always successful --- there are a whole host of things that can go wrong with creating pretty much any object, so it's always worth checking any association or variable really. Glad I could help.

Lewis

Answers (0)