cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Issue using PersistableAdapter to set an int

sdrzewiczewski
7-Bedrock

Issue using PersistableAdapter to set an int

For a few workflows I've created methods to set an object's attribute (one for String, one for TimeStamps) which have worked great over the past few years. I have a new requirement to set an int's value. I created a new method and changed the input attribute to accept an int. When I call the method, i get an odd error telling me I've violated the limit constraint. The value I'm sending is 2 which should not cause any issues.

 

wt.system.err Administrator - com.ptc.core.meta.container.common.ConstraintException: The value for Number Of Cavities must be between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807, inclusive.

 

The method i have is the following

	public static void setAttributeValue(WTObject pbo, String IBAName,int IBAValue) {
		PersistableAdapter obj;
		try {
			obj = new PersistableAdapter(pbo, null,Locale.US, new UpdateOperationIdentifier());
			obj.load(IBAName);
			System.out.println("Attribute " + IBAName + " value is " + IBAValue);
			obj.set(IBAName,IBAValue);
			obj.apply();
			PersistenceHelper.manager.modify(pbo);
		} catch (WTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NullPointerException e) {
			System.out.println("Null Pointer Encounterd In Code");
			e.printStackTrace();
		}
	}

This method is called by the following method to checkout the doc and check it in

 

	public static String setFaiDocumentAttributes(WTDocument doc,String checkinComment,String attName,int attValue,Boolean checkinDoc) {
		try {
			if (WorkInProgressHelper.service.isLocked(doc) == false) {
				doc = (WTDocument)WorkInProgressHelper.service.checkout(doc,WorkInProgressHelper.service.getCheckoutFolder(), "").getWorkingCopy();
			} else {
				doc = (WTDocument)WorkInProgressHelper.service.	workingCopyOf(doc);
			}
			ChangeWorkflowHelper.setAttributeValue(doc,attName,attValue);

			checkinComment += attName + ": " + attValue + "\n";

		} catch (WTPropertyVetoException | WTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		if (checkinDoc) {
			 try {
				wt.vc.wip.WorkInProgressHelper.service.checkin(doc, checkinComment);
			} catch (WorkInProgressException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (WTPropertyVetoException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (PersistenceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (WTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }

		return checkinComment;
	}

 

Through the UI, I can set the attribute to the value 2. I've also added a limit constraint from 0 - max int size and the error message using the API was still showing the range violation of -max int size - positive max int size. 

 

3 REPLIES 3

What happen if you use an Integer class instead of a primitive int?

HI,

 

Can you please try to set the integer like this :

obj.set("integerValue", new java.lang.Long(222));

 

I saw that here "Modifying PBO Attributes With Workflow Variables (Set) " :

 

 

 

wt.part.WTPart part = (wt.part.WTPart)primaryBusinessObject;

//get check out folder for the current user in the session
wt.folder.Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();
//check out object 
wt.vc.wip.CheckoutLink chklink = wt.vc.wip.WorkInProgressHelper.service.checkout(part, checkoutFolder, "cehcek out comment");
wt.part.WTPart wrk = (wt.part.WTPart) chklink.getWorkingCopy();
System.out.println("\nChecked out WTPart ......"+wrk.getName()+"\t"+wrk.getCheckoutInfo());

com.ptc.core.lwc.server.PersistableAdapter pbo = new com.ptc.core.lwc.server.PersistableAdapter(wrk, null, null, null);
System.out.println("\nGot pbo...."+pbo.toString());
pbo.load("StringAttribute","BooleanAttribute","DateAttribute","IntegerAttribute");

System.out.println("Loading Attributes");
System.out.println("StringAttribute : "+pbo.get("StringAttribute"));
System.out.println("BooleanAttribute : "+pbo.get("BooleanAttribute"));
System.out.println("DateAttribute : "+pbo.get("DateAttribute"));
System.out.println("IntegerAttribute : "+pbo.get("IntegerAttribute"));

pbo.set("StringAttribute", StringAttributeVariable);
pbo.set("BooleanAttribute", BooleanAttributeVariable);
pbo.set("IntegerAttribute", new java.lang.Long(IntegerAttributeVariable));

java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat SHORT);
String tempDate= DateAttributeVariable;
java.util.Date objectDate = df.parse(tempDate);
pbo.set("DateAttribute", new java.sql.timestamp(objectDate.gettime()));

wt.fc.Persistable p = pbo.apply();
//modify attributes to database
wt.fc.PersistenceHelper manager.modify(p);
// check in document
wt.vc.wip.WorkInProgressHelper.service.checkin((wt.vc.wip.Workable) p, "check in comment");

} catch (wt.util.WTException e){
e.printStackStrace();
}catch (wt.util.WTPropertyVetoException e){
e.printStackTrace();
}

 

Good luck

 

That did the trick! Thanks for the quick reply

Top Tags