PrimaveraXERFileWriter: Primavera P6 / Desktop (v21,v22) - project can't be opened
alex-matatov opened this issue · comments
I noticed that in some cases P6 xer file could not be imported to P6/Desktop (however the same project exported as xml via PrimaveraPMFileWriter could be imported without any issue):
Case 1
When a MPXJ/ProjectFile
has 2 or more WBS (MPXJ/Task
) without parent (root ones). In this case P6/Desktop fails to import xer with error like that:
Import Failed: The import file contains projects with invalid parent WBS IDs. The following WBS nodes do not have a valid parent_wbs_id in the wbs_id field:
Project: 1 - WBS: 37380
Project: 1 - WBS: 37381
P6/Desktop successfully imports XML file with 2 WBS without parent. When P6/Desktop exports this Project as XER it adds an additional root WBS with wbsName == projectName and adds these 2 WBS as children.
Basically, I think the code below could be a fix in PrimaveraXERFileWriter
var wbsWithoutParent = project.getTasks().stream()
.filter(t -> t.getActivityType() == null)
.filter(t -> t.getParentTask() == null)
.toList();
if (wbsWithoutParent.size() < 2) {
// there is no or only one wbs without parent (root). So we don't need to do anything there
return;
}
// there are several wbs without parent. So we need to create a root wbs and add them as children
var rootWbs = project.addTask();
rootWbs.setUniqueID(wbsUniqueId);
rootWbs.setActivityID(project.getProjectProperties().getProjectID());
rootWbs.setName(project.getProjectProperties().getName());
rootWbs.setSequenceNumber(0);
wbsWithoutParent.forEach(rootWbs::addChildTask);
Case 2
When Task.name
or Resource.name
has "
character (for example 15" pipe
) and PrimaveraXERFileWriter writes it as it then P6/Desktop can't import it or displays a record weirdly.
Basically, "
characters should be escaped (doubled -> 15"" pipe
) otherwise XER format is broken.
@alex-matatov thanks for investigating and documenting these issues. I have applied fixes for both of them.
The fix for the WBS hierarchy is based loosely on your original code, although I've made the addition of a new parent WBS entry a temporary thing, so in theory the the schedule objects will be unchanged after they have been written to an XER file. I also ensured that any top level activities were also made children of the new WBS entry to ensure that the whole schedule is seen as being "pushed down" the hierarchy by one level. Without this change activities and WBS entries which were originally at the same level of the hierarchy would have ended up split across different levels - hope that makes sense!
Hi Jon,
Thank you for the quick fix and looking forward for the new mpxj version!
Cheers,
Alex
New version available now with this change.
Hi Jon,
I just checked - it works!
Cheers,
Alex