To further a bit more of what Steven shared, here is a good tutorial on Java method overloading
https://www.w3schools.com/java/java_methods_overloading.aspSo JavaScript does not have the concept of method overloading, so the Nashorn/Rhino engine has to map between the two and make its best guess as to which overloaded method to call.
If you pass in a value like "null" into the setValue method on an Mbo, that can map to many different Java types and you will get the following error.
java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(java.lang.String, psdi.mbo.MboRemote), (java.lang.String, byte[]), (java.lang.String, java.lang.String), (java.lang.String, psdi.mbo.MboSetRemote), (java.lang.String, java.util.Date)] of the method psdi.app.workorder.WO.setValue for argument types [java.lang.String, null]"}}
What this is saying is that it can't map "null" unambiguously because it matches several different method signatures with the same method name.
Understanding that each function / method on a Javascript object is really just part of a Map structure you can then reference the specific function on that Map by its full signature.
For example if you want to set the value of a description on an Mbo variable called
mbo
and that value may occasionally be null or undefined you can make the standard
mbo.setValue("DESCRIPTION", "Your value here")
call like the following,
mbo["setValue(String, String)"]("DESCRIPTION", "Your value here");
. In this example you are explicitly referencing the function called
setValue
that takes two
String
type arguments and disambiguates which method you are trying to call.
Hope that helps someone out there.
Jason
------------------------------
Jason VenHuizen
------------------------------
Original Message:
Sent: Thu December 02, 2021 08:55 AM
From: Steven Shull
Subject: Why is there a generic mbo.setValue() method, but not a generic mbo.getValue() method?
When you call setValue, it's an overloaded method. That means that the method exists multiple times with support for different parameter amounts and types being passed in. For example, you can call:
mbo.setValue("ATTRIBUTENAME","STRINGVALUE")
or
mbo.setValue("ATTRIBUTENAME",0.0)
While the method is named the same, completely different code is being invoked in the class. The first is looking for a method called setValue that accepts two string parameters. The second is looking for a method that accepts one string parameter and one decimal parameter.
For retrieving, Java can't return different data types inside of a function. You have to declare the return data type as part of the function declaration. Without providing different parameter data types or number of parameters, therefore overloading that function, you're limited to 1 return type. What some products do, including Maximo, is they create a class that they use as the return type instead. While you can't call getValue(), you can call mbo.getMboValue("ATTRIBUTENAME") which will return the MboValue class for that attribute. This includes a lot of useful functions beyond getting the value (getting the previous value, column title, data type, etc.). But you still need to call getString() for example to get the actual value in the format you want.
You can call getString on every field but knowing and retrieving the appropriate data type is important. For example, values displayed in text boxes are displayed via getString(). For a date based field this will cause the date to render appropriately for that specific user with their configuration (IE 2021-12-02 or 12/2/2021). Similar for currency based fields where in the US it would be displayed as 10.75 but in France it would be displayed as 10,75. Even Boolean fields are fun because Y/N doesn't make sense in every language so that would also change based on the language of the user.
------------------------------
Steven Shull
Original Message:
Sent: Wed December 01, 2021 10:52 PM
From: User1971
Subject: Why is there a generic mbo.setValue() method, but not a generic mbo.getValue() method?
MAM 7.6.1.2:
A novice question:
In the Maximo Java API, there is a generic method called mbo.setValue(). We don't need to specify the datatype when using that method.
Out of curiosity, is there a reason why we don't have a generic GET method too? (there isn't a mbo.getValue() method)
Instead, we need to use GET methods that are for specific datatypes:
- mbo.getString("DESCRIPTION")
- mbo.getInt("WOPRIORITY")
- mbo.getLong("WORKORDERID")
- mbo.getDouble("MEASUREMENTVALUE")
- mbo.getDate("TARGSTARTDATE")
- mbo.getBoolean("HASPARENT")
Just wondering. Thanks.
#Maximo
#AssetandFacilitiesManagement