0

Good Morning everyone,

Does anyone know on how to use MPXJ v5.1.5 to effectively to read the MPP. project file to get the Outline Code Values linked to their assigned tasks.

I already have found a way of getting the tasks and the time scale data for them but how do I find out what Outline Code or custom field is linked to any task? This will help to create reports on how these custom fields are going.

Here is my main piece of code used to retrieve the Tasks with their time scale data. This piece of code is running on a Background worker and report progress.

    void Work_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Document_Details_To_Open Document_Selected_Details = e.Argument as Document_Details_To_Open;
                ProjectReader reader = ProjectReaderUtility.getProjectReader(Document_Selected_Details.FileName);

                MPXJ.ProjectFile mpx = reader.read(Document_Selected_Details.FileName);

                int count = mpx.AllTasks.Size();
                int stepsize = 100002 / count;
                int pos = 1;

                foreach (MPXJ.Task task in mpx.AllTasks.ToIEnumerable())
                {
                    Task_Type task_ = new Task_Type()
                    {
                        Name = task.Name,
                        Total_Days = task.Duration.toString(),
                        ID = task.ID.toString()
                    };

                    //Task.getFieldByAlias()

                    //can add task above to MVVM connection
                    foreach (MPXJ.ResourceAssignment Resource in task.ResourceAssignments.ToIEnumerable())//this will only run once per task , I use the ResourceAssignment variable to get the duration data
                    {

                        //use the selected document details given
                        Dictionary<string, java.util.List> worklist = new Dictionary<string, java.util.List>();
                        foreach (string Work_type in Document_Selected_Details.Data_To_Import)
                        {
                            worklist.Add(Work_type, Get_Some_work(Resource, Work_type));
                        }

                        int Length_of_data_to_retrieve = Get_Time_Scale_int(Document_Selected_Details.Time_Scale_Units, task.Duration.Duration);

                        TimescaleUtility TimeScale = new TimescaleUtility();
                        java.util.ArrayList datelist = TimeScale.CreateTimescale(task.Start, Get_Scale_Type(Document_Selected_Details.Time_Scale_Units), Length_of_data_to_retrieve);
                        MPXJ.ProjectCalendar calendar = Resource.Calendar;
                        TimephasedUtility utility = new TimephasedUtility();

                        Dictionary<string, java.util.ArrayList> durationlist = new Dictionary<string, java.util.ArrayList>();
                        foreach (KeyValuePair<string, java.util.List> item in worklist)
                        {
                            java.util.ArrayList duration = utility.SegmentWork(calendar, item.Value, Get_Scale_Type(Document_Selected_Details.Time_Scale_Units), datelist);
                            durationlist.Add(item.Key, duration);
                        }

                        Dictionary<string, List<string>> ssss = new Dictionary<string, List<string>>();
                        foreach (var s in durationlist)
                        {
                            string key = s.Key;
                            List<string> Hours = new List<string>();
                            foreach (var hours in s.Value.toArray().ToList())
                            {
                                Hours.Add(hours.ToString());
                            }
                            ssss.Add(key, Hours);
                        }

                        Task_With_All all = new Models.Task_With_All()
                        {
                            Task_Name = task.Name,
                            Time_Step_Type = Document_Selected_Details.Time_Scale_Units,
                            Duration_List = ssss,
                            StartDate = task.Start.ToDateTime().ToString(),
                            Total_duration = Length_of_data_to_retrieve.ToString()
                        };
                        Task_With_All_list.Add(all);
                        //I have now every task and their Time scale data but I still need to know if the tasks could have custom fields connected or not

                    }
                    pos += stepsize;
                    Work.ReportProgress(pos);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Any help would be greatly appreciated.

TommyB
  • 5
  • 6
  • Are you looking to retrieve the value of a custom field (like for example Text1) which has an alias in Microsoft Project, so for example the user sees it as "Fred" rather than "Text1"? – Jon Iles Sep 02 '15 at 18:03
  • Yes , what I am looking for exactly is the outline code's values, I want to use the outline codes to group tasks together, like a filter. Example outline code 1 has an alias of "Electrical" so all the tasks with that outline code can be filtered and grouped together. – TommyB Sep 07 '15 at 07:24
  • Does `Task.getOutlineCode(n)` give you what you want? (where n is between 1 and 10, for the ten custom outline codes associated with each task) – Jon Iles Sep 07 '15 at 09:23
  • Yes , That worked Thanks alot , I did test that method before but never really knew what result I was to suppose to get. I see when you use `Task.getOutlineCode(n)` and use the `int` values from 1 to 10 the outline codes assigned to the task will show as text and the others will show `null`. I Always used the wrong index int values in my tests. Thanks again this helped a lot. – TommyB Sep 07 '15 at 09:48

1 Answers1

0

Thanks to Jon Iles, the answer on how to get the Outline Codes for a Task became very simple. In MS Project there is a limit of 10 Outline Codes the users can assign to Tasks. To Get these Outline Codes that has been Assigned to a Task using MPXJ v5.1.5, you can use this to get them :

//this code comes from my code block in the question.
...
foreach (MPXJ.Task task in mpx.AllTasks.ToIEnumerable())
{
    //if the string values retrieved from these has a valid value that's returned, that value is the Outline Code assigned to the task 
    string Outline_code_1  = task.GetOutlineCode(1);
    string Outline_code_2  = task.GetOutlineCode(2);
    string Outline_code_3  = task.GetOutlineCode(3);
    string Outline_code_4  = task.GetOutlineCode(4);
    string Outline_code_5  = task.GetOutlineCode(5);
    string Outline_code_6  = task.GetOutlineCode(6);
    string Outline_code_7  = task.GetOutlineCode(7);
    string Outline_code_8  = task.GetOutlineCode(8);
    string Outline_code_9  = task.GetOutlineCode(9);
    string Outline_code_10 = task.GetOutlineCode(10);
}
...
TommyB
  • 5
  • 6