Tuesday 5 May 2015

Automation script integer variables

When I started writing a auto script to copy one INTEGER value into another INTEGER value, I feel that it is very easy to do. Offcourse it is easy, except you are able to solve the below error:

java.lang.ClassCastException: java.math.BigInteger incompatible with java.lang.String

I will explain you in detail, when you will face this error

For example, in work order I would like to set wopriority and assetlocpriority based on work type.

Created a attribute launch point script.

Variables declared as follows:

object is WORKORDER

wp = WOPRIORITY
alp = ASSETLOCPRIORITY
worktype = WORKTYPE

Script as follows:
#Script is for if work type is CM, then copy assetlocpriority to wopriority

if worktype == "CM":
 wp = alp

# Here you will get a error that
"java.lang.ClassCastException: java.math.BigInteger incompatible with java.lang.String"

This is because auto script considering these wp and alp as longs. I am not sure why it is like that and why it is throwing an error.
Hence I tried to print it.

print wp
#output is 2L
print alp
#output is 4L

From above output, I felt that, error is because of "L". Hence I tried to change to output without "L" like 2 and 4

So I did casting with integer like int(alp), it is printing output as "2" (without "L")

Corrected Script as follows:
#Script is for if work type is CM, then copy assetlocpriority to wopriority

if worktype == "CM":
 wp = int(alp)

Now it is working fine. No error.

 

No comments:

Maximo SOAPUI error javax.xml.ws.WebServiceException

SOAPUI error while sending payload to below url (in cluster environment) http://localhost:9080/meaweb/services/MXASSET Error : <f...