joniles / mpxj

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

Writing ProjectFile to XER format does not update the task #481

Closed iMohannad closed 1 year ago

iMohannad commented 1 year ago

Hi,

I have a XER project file and I am trying to update the cost in a specific task. I can read the cost succesfully and update it using task.setCost(). However, when I write the ProjectFile into an external XER file, the cost is not updated.

Here's the code example where I try to change any task where the cost is 3000 to 7000:

using net.sf.mpxj;
using java.io;
using net.sf.mpxj.primavera;

namespace XerReader
{
    class XerReader
    {
        static void Main(string[] args)
        {
            // Load the XER file
            PrimaveraXERFileReader reader = new PrimaveraXERFileReader();
            ProjectFile project = reader.read("test.xer");

            TaskContainer taskContainer = project.getTasks();

            foreach (net.sf.mpxj.Task task in taskContainer)
            {

                net.sf.mpxj.Task task1;
                if (task.getCost() != null && task.getCost().intValue() == 3000) {
                    task1 = project.getTaskByUniqueID(task.getUniqueID());
                    task1.setCost(java.lang.Double.valueOf(7000));

                }
            }

            PrimaveraXERFileWriter writer = new PrimaveraXERFileWriter();
            writer.write(project, "test_updated.xer");
        }
    }
}
joniles commented 1 year ago

Hello! Thanks for getting in touch.

I think the issue is that P6 derives the cost shown at the activity level from the activity's resource assignments and expense items. You can see how MPXJ generates the cost when reading an XER file in the code shown here and here. My understanding is that P6 would be doing something similar when it reads an XER file. Based on that information, you'd need to modify the expense items or resource assignments for your activity in order to change the cost shown in P6.

Hope that helps!