Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Ian Pletcher Absent Member.
Absent Member.
2855 views

Accessing a UDA from the SDK

I am trying to access the value of user defined attribute via the Caliber SDK (for Version 10).

I have written Java that sets an attribute object with the attribute concerned and I think the method I need to get the value is .getFieldValue. However when I call the method, the Caliber SDK throws an exception.

It is unclear from the documentation exaclty what parameter is required for the .getFieldValue  -  I have interpreted the documentation, that parameter is a string containing the name of the attribute. Is this correct? The exception thrown is:

java.lang.IllegalArgumentException: Unable to obtain field: Notes from class: class com.starbase.caliber.attribute.UDAText

Any ideas what I might be doing wrong?

 

0 Likes
3 Replies
Ian Pletcher Absent Member.
Absent Member.

RE: Accessing a UDA from the SDK

OK I have now resolved my own problem. I have completely mis understood that part of the object model.

The Attribute object is really an object describing the attribute type.

In order access the value of a UDA from the AttributeValue object type you have to cast the Attribute value to the object for the specific user defined attribute type. Since my UDA was a text field, the AttributeValue object has to be cast to a UDATextValue object type.

I would suggest that the documentation for the SDK could be improved to make this clearer. I only stumbled across the right answer after a fair amount of trial and error.

0 Likes
Ina Absent Member.
Absent Member.

RE: Accessing a UDA from the SDK

Hello Ian,

i have read you solution. I have the same problem but can't resolve it. Can you help me?

There is my code:

AttributeValue[] attributevalues = requi.getAttributeValues();

               for(int j = 0; j <attributevalues.length; j++){

                   AttributeValue attributevalue =  attributevalues;

                   System.out.println("\t Attribute Name: " + attributevalue.getAttribute().getName());

                   Attribute attribute =attributevalue.getAttribute();

                   System.out.println("\t Attribute: " + attribute.getDescription());

                   System.out.println("\t Attribute: " + attribute.getUITypeName());

                   UDATextValue attrs = (UDATextValue) attribute.getFieldValue("Target Version");

                   System.out.println("\t Attribute: " + attrs.getValue());

                   }

requi is the requirement.

The user defined attribute  "Target Version" is a single text line.

I get the error-message:

Exception in thread "main" java.lang.IllegalArgumentException: Unable to obtain field: Target Version from class: class com.starbase.caliber.attribute.UDAText

What's wrong on this code?

0 Likes
SupremeSpod Absent Member.
Absent Member.

RE: Accessing a UDA from the SDK

The following code may give you some help.

It isn't very efficient but it may give you some clues.

// method to retrieve the value of a particular field
// m_AttributeValues is initialised in the constructor
// returns a "string" representation of the value
// "" if no value found.
public string GetCustomFieldValue(string custFieldName)
{
string ret_string = "";

foreach( AttributeValue av in m_AttributeValues )
{
if (av.Attribute.Name.Equals(custFieldName))
{

// If any more types are required then add suitable code here
// Determine the type
if (av is UDAListValue)
{
UDAListValue value = (UDAListValue)av;
ret_string = value.SelectedValue.ToString();
}
else if (av is UDABooleanValue )
{
UDABooleanValue value = (UDABooleanValue)av;
ret_string = value.Value.ToString();
}
else if (av is UDADateValue )
{
UDADateValue value = (UDADateValue)av;
ret_string = DateTime.FromOADate(value.OLEDate).ToShortDateString();
}
else if (av is UDAIntegerValue)
{
UDAIntegerValue value = (UDAIntegerValue)av;
ret_string = value.Value.ToString();
}
else if (av is UDATextValue)
{
UDATextValue value = (UDATextValue)av;
ret_string = value.Value;
}
else if (av is UDADurationValue )
{
UDADurationValue value = (UDADurationValue)av;
ret_string = value.Value.ToString();
}
else if (av is UDAFloatValue)
{
UDAFloatValue value = (UDAFloatValue)av;
ret_string = value.Value.ToString();
}
}
}
// default ret
return ret_string;
}
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.