joniles / mpxj

Primary repository for MPXJ library
http://www.mpxj.org/
GNU Lesser General Public License v2.1
249 stars 104 forks source link

ResourceAssignment is not added when exporting to Primavera in MSPDI format #754

Closed kolovrat566 closed 1 month ago

kolovrat566 commented 1 month ago

I am facing a problem when exporting to mspdi When I add a ResourceAssignment to a task using the following code:

      Resource assignedResource = file.addResource();
      assignedResource.Name = "Assigned Resource";

      Task parent = file.addTask();
      parent.Name = "Parent";

      Task task = parent.addTask();
      task.Name = "StackOverflow Example Task";
      task.Start = CreateDate("2023-10-19T23:59:00");
      task.Duration = Duration.getInstance(3, TimeUnit.DAYS);
      task.Work = Duration.getInstance(15, TimeUnit.HOURS);
      task.RemainingWork = Duration.getInstance(15, TimeUnit.HOURS);

      double hoursPerDay = 8.0;
      double hoursWorkedPerDay = 5.0;

      ResourceAssignment resourceAssignment = task.addResourceAssignment(assignedResource);
      resourceAssignment.Start = CreateDate("2023-10-19T23:59:00");
      resourceAssignment.Work = Duration.getInstance(15, TimeUnit.HOURS);
      resourceAssignment.RemainingWork = Duration.getInstance(15, TimeUnit.HOURS);
      resourceAssignment.Units = NumberHelper.getDouble((hoursWorkedPerDay / hoursPerDay) * 100.0);

When I'm importing into Primavera I get the following error: (I use: net.sf.mpxj-for-csharp: 13.4.0, MSPDIWriter to create the file)

Resource: Key: 1 missing required related object CurrencyNameId. Rejecting
Resource 'Resource: Key: 1' not imported

However, if you create a file in xer format, there is no error. (I am attaching a file with import information) 8b023e0f-7f55-420d-aa5f-724ab0732b05.xml.DetailImportLog.txt

Thanks in advance, let me know if you need more detailed information

joniles commented 1 month ago

Looking at the log file you provided I wonder if this might be due to the file type you are importing:

Executing Import of Type: MSP
=================================================================================================================
Business Object                            Import Option                 Specific            Delete Unreferenced
=================================================================================================================

This seems to suggest that you are importing an MSPDI file into P6? Ideally you need to be generating a PMXML file and importing that. When I import a sample PMXML file into my copy of P6 this is what the log file says:

Executing Import of Type: Flat
=================================================================================================================
Business Object                            Import Option                 Specific            Delete Unreferenced
=================================================================================================================
kolovrat566 commented 1 month ago

Looking at the log file you provided I wonder if this might be due to the file type you are importing:

Executing Import of Type: MSP
=================================================================================================================
Business Object                            Import Option                 Specific            Delete Unreferenced
=================================================================================================================

This seems to suggest that you are importing an MSPDI file into P6? Ideally you need to be generating a PMXML file and importing that. When I import a sample PMXML file into my copy of P6 this is what the log file says:

Executing Import of Type: Flat
=================================================================================================================
Business Object                            Import Option                 Specific            Delete Unreferenced
=================================================================================================================

Sorry for the inaccuracy, the file is exported in the Microsoft Project XML format (in the Primavera application)

joniles commented 1 month ago

So as I understand it, you are exporting an MSPDI file (the Microsoft XML format) from P6, processing this file with MPXJ, then writing it from MPXJ as an MSPDI file, then re-importing it into P6 - is that correct?

kolovrat566 commented 1 month ago

No, i create a file with MPXJ in mspdi format and try to import it into P6

joniles commented 1 month ago

OK, I think you should be writing a PMXML file rather than an MSPDI file if you are intending to import your schedule into P6.

My understanding of the error you are seeing is that a resource can have a currency associated with it, but for whatever reason this is failing when you import the MSPDI file. Microsoft Project doesn't support the concept of currencies, so there is no currency information present in an MSPDI file. When importing MSPDI files P6 must be doing something as part of its own import process to set up currency correctly, which appears not to be working in this case.

If you create a PMXML file, all of this is taken care of for you.

kolovrat566 commented 1 month ago

Thank you very much for your time, you were absolutely right, the error is on the P6 side, when importing into Microsoft Project (app), everything works fine