cancel
Showing results for 
Search instead for 
Did you mean: 

Setting new lineItem's field referencing a VLV

Former Member
0 Kudos

Hi,

My scenario is on a Toolbar script and on a MasterAgreement context (1004).

Issue is when I try to create an new object reference to set to a null valuelistvalue value for a lineItem that I had just added to the master agreement I get the following error:

ClassCastException:Illegal cast. Cannot cast com.frictionless.common.db.ObjectReference to com.frictionless.api.common.types.LocalizedObjectReferenceIfc.

I need to set Item_Cat field in a lineItem to a certain default value depending on certain conditions.When I call the IBeanFieldMdIfc.get() method I get com.frictionless.api.common.types.LocalizedObjectReferenceIf and it is only logical to use the same type when you try to set it some value. Right?

Here is what I do when this generates an error.

IBeanFieldMdIfc itemCat = (IBeanFieldMdIfc)lineItem.getFieldMetadata("ITEM_CAT");

LocalizedObjectReferenceIfc locObjRef = (LocalizedObjectReferenceIfc)itemCat.get(lineItem);

This shows me the displayed value in the vlv dropdown if the lineItem already exists and null if the lineItem is new.

Now I try to set the new lineItem vlv value like this:

com.frictionless.api.common.types.TypeFactory fact = new TypeFactory();

objectID = -2147482685;//getObjectId("custom$Service", "Item Category");

objRef = fact.createObjectReference(616, objectID,"Service");

itemCat.set(lineItem, objRef);// This line generates a ClassCastException:Illegal cast. Cannot cast com.frictionless.common.db.ObjectReference to com.frictionless.api.common.types.LocalizedObjectReferenceIfc.

Notice the two different package names, question where the hell does CLM get the com.frictionless.common.db.ObjectReference because it does not even get imported into the script.

I am now confused please assist.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I think I have figured out what the issue is with this.

The TypeFactory Class used to create instances of ObjectFactoryIfc, for instance the static TypeFactory.createObjectReference() method, uses the com.frictionless.common.db.ObjectReference to create instances of com.frictionless.api.common.types.ObjectReferenceIfc, which is wrong. Unless I am missing something.

This in turn causes the reflection error when trying to set the field value for IBeanMdIfc bean for the field Item_Cat. Because the object types are not the same. My script is looking ObjectReferenceIfc which is a superclass of LocalizedObjectreferenceIfc but the TypeFactory.createObjectReference returns the com.frictionless.common.db.ObjectReference instead.

Unless there is another way to create the ObjectReferenceIfc instance instead of using t TypeFactory Class.

Please assist I am going out of my mind.

0 Kudos

Hi Tebogo,

If I understand the requirement correctly, you would like to set a default value to the Item Category field on the MA line item. Item Category is a value list. You don’t need to use TypeFactory here. Use the findUniqueByNameType method on value list home ValueListValueIBeanHomeIfc class. This should return a ValueListValueIBeanIfc. On ValueListValueIBeanIfc you should see a method to get the object reference. So in your set method you could do something like this…

itemCat.set(lineItem, vlv.getObjectReference()) where vlv is the ValueListValueIBeanIfc.

Hope this helps.

Regards,

Vikram

Former Member
0 Kudos

This worked perfectly.

Thanks Vikram.

Much apperciated

Answers (0)