Skip to main content
19-Tanzanite
August 24, 2022
Question

Get Long Attribute to int Attribute

  • August 24, 2022
  • 4 replies
  • 1622 views

I can get a string attribute from the Change Activity to the workflow.  How do I convert a long attribute to an int attribute?  Code for string is below where attribute is the attribute in the change activity and att1 is the attribute in the workflow.

 

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null,java.util.Locale.US,null);

obj.load("attribute");

att1 = (String) obj.get("attribute")

 

 

4 replies

HelesicPetr
22-Sapphire II
22-Sapphire II
August 24, 2022

Hi @BrianToussaint 

What error is shown in a log if the Long parameter is not converted to a int? 

 

does it really the java.lang.Long or is it different type as float,  double and so on.

 

PetrH

HelesicPetr
22-Sapphire II
22-Sapphire II
August 24, 2022

Hi @BrianToussaint 

I've checked some my workflows and I always use the .toString() operation. 

String tested_km = obj.get("tested_km").toString();

After I get value I work with string even it is number, double, int, or whatever.

It helps to avoid typeo errors in WF but also depends on the attribute type. Not all are eligible to use .getString().

 

PetrH

17-Peridot
August 24, 2022

I would suggest to get the long value and then get the integer:

 

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null,java.util.Locale.US,null);
obj.load("attribute");
long att1 = (long) obj.get("attribute")
int intValue = att1.intValue();

 

13-Aquamarine
August 29, 2022

Hi BrianToussaint,


 

I wanted to follow up with you on your post to see if your question has been answered.

If so, please designate the appropriate post as the Accepted Solution for the benefit of other members who may have the same question.

If not, please post your current status in the public thread so that we can continue to support.


 

Thanks,

Iuliana