Skip to Content
avatar image
Former Member

Setting new lineItem's field referencing a VLV

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jul 19, 2012 at 09:57 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded