joniles / mpxj

Primary repository for MPXJ library

Home Page:http://www.mpxj.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XER FieldType mismatch in newer releases

darthWes opened this issue · comments

I have an XER reading capability that I have been slow to update, shame on me; I'm experiencing an issue upgrading past MPXJ 11.0. It's likely that I'm not understanding something basic, and that's OK with me; please give me the brutal truth.

So, back before MPXJ 11.0, I would read out the user's custom field info. I would get the field id, the alias (user readable field name), the field's data type (int/string), and the project mapped field name (this would be like TEXT4 or NUMBER3 or whatever).

Now in MPXJ 12.5 (but anything past MPXJ 11.0), I'm getting a different mapped field name (FieldType). Instead of "TEXT9" I'm getting some other strange values.

(1) How can I get (can I get) the old value using MPXJ 11+?
(2) Why does it seem to have dissapeared? I've tried reading the code, and comparing the code changes, but I've determind my time would be better spent posting the question before continuing my trek through the code base. Generally, Jon's code is easy enough to read, but I'm not seeing how the heck these values are read and how that would be getting a different value. From what I can see, udf_type_label seems to be the same index across versions. Is there a document somewhere that can explain this sort of thing?

At risk of going overboard, here's a basic outline:


public void readSimple(String fileName) {
		try {
			ProjectReader reader;
			ProjectFile project;

			/**
			 * Is there a utility class/method I can call to auto-magically grab
			 * the right reader?
			 */
			if (fileName.endsWith(".xer")) {
				reader = new PrimaveraXERFileReader();
			} else {
				reader = new MPPReader();
			}
			project = reader.read(fileName);

			/**
			 * Basic C-style declaration for the variables I need. Is there some
			 * kind of preference for declaration and instantiation ?
			 */
			CustomFieldContainer cfContainer = null;
			Iterator<CustomField> iterator = null;
			CustomField myCustomField = null;
			FieldType fieldType = null;
			int fieldID = -1;
			String fieldAlias = null, fieldTypeName = null, fieldTypeNameInternal = null, fieldDataType = null;

			//Grab the fields, walk over them:
			cfContainer = project.getCustomFields();
			iterator = cfContainer.iterator();
			while (iterator.hasNext()) {
				myCustomField = iterator.next();

				//If we got a custom field, read it's relevant attributes:
				if (myCustomField != null) {
					fieldID = myCustomField.getUniqueID();
					fieldAlias = myCustomField.getAlias();
					fieldType = myCustomField.getFieldType();
					fieldDataType = fieldType.getDataType().toString();
					fieldTypeName = fieldType.getName();
					fieldTypeNameInternal = fieldType.name();

					//These are good values, seem to be working fine:
					System.out.println("fieldID: " + fieldID);
					System.out.println("fieldAlias: " + fieldAlias);
					System.out.println("fieldDataType: " + fieldDataType);

					/**
					 * Here's where I'm getting different values in MPXJ 11+.
					 * For mpp (microsoft project) files, it gives the expected
					 * values, but xer files are now giving me different answers
					 * on the same file using MPXJ < 11 and > 11.
					 *
					 * For example, I used to get "number3" here for my field,
					 * but now, with MPXJ 11+, I'm getting the field alias as
					 * fieldTypeName, and user_field_{number} for the
					 * fieldTypeNameInternal.
					 */
					System.out.println("\n-> Looking here to see NUMBER3 or similar value <-");
					System.out.println("* fieldType: " + fieldType);  //Warm
					System.out.println("* fieldTypeName: " + fieldTypeName); //Cold
					System.out.println("* fieldTypeNameInternal: " + fieldTypeNameInternal); //??

					System.out.println("\n----------");
				}
			}
		} catch (Exception exc) {
			exc.printStackTrace(System.out);
		}
	}


So, I'll show you some output I'm getting.
From MPXJ 10.12:

fieldID: 870
fieldAlias: IPM Exemptions
fieldDataType: NUMERIC

-> Looking here to see NUMBER3 or similar value <-
* fieldType: Number1
* fieldTypeName: Number1
* fieldTypeNameInternal: NUMBER1

And, using the same xer file, the output I'm getting from MPXJ 12.5:

fieldID: 870
fieldAlias: IPM Exemptions
fieldDataType: NUMERIC

-> Looking here to see NUMBER3 or similar value <-
* fieldType: IPM Exemptions
* fieldTypeName: IPM Exemptions
* fieldTypeNameInternal: user_field_870

Can anyone help me understand? It looks like the internal field type name might be what I'm after. However, I want to get the same answer I used to get, NUMBER1 in this example, not user_field_870. Have we lost the ability to read that or is there some way I can access it?

Thanks!

Hello! I'll jot down some quick notes here which will hopefully get you going, I can give you a more considered answer referencing your actual code at the end of the week when I've finished a couple of other things I'm working on.

The short answer is that MPXJ switched to using a separate class to represent user defined fields, rather that trying to map these types of fields to the various Text1-10, Date1-10 etc custom fields used by Microsoft Project. This allows us to support arbitrary numbers of Enterprise Custom Fields (Microsoft project) and User Defined Fields (P6, Powerproject etc).

You may find these notes helpful: https://www.mpxj.org/howto-use-fields/, and in particular the sections from here onwards https://www.mpxj.org/howto-use-fields/#custom-fields

Thanks, Jon! I think that is enough information.

After I wrote this up, I found a similar note in the changes report page that led me to believe you were going to give me this answer. I'm not sure why the changelog and changes pages are different, but the changelog note wasn't as good for me. (https://www.mpxj.org/CHANGELOG/ and https://www.mpxj.org/changes-report.html)

Thanks for your time!