cancel
Showing results for 
Search instead for 
Did you mean: 

Reflection errors in Field Data Edit Scripting context(Line Item class)

0 Kudos

Hello Experts,

I have a script that does some validation in the Field Data Edit Scripting context of the "Line Item" class, and I have "MATERIAL" as my target. when i try throwing an Application Exception in this context I get a reflection error message box instead of the message I have passed to the Application Exception constructor.

your help will be greatly appreciated.

kind regards,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thabiso,

Can you put that text of that error box here. Some part of your code can also help.

Thanks

Devesh

0 Kudos

Hi Devesh

thank you for your response.

The error code is:

000000000000002147: A reflection error occurred accessing the object.

Script Details:

1. Scripting Context: Field Data

2. Class: Line Item(1007)

3. Target: MATERIAL

The script only shows the reflection error when I throw an exception, so even a simple code:

throw new ApplicationException("Hello world");

does not work.

regards,

0 Kudos

Hi Kamanga,

An application exception should be thrown as shown below:

doc.createApplicationException("field id", "resource id");

If you want to accumulate multiple exceptions, you can create a single ApplicationException and chain the exceptions. You might want to read the scripting guide available on the SMP. SAP offers training(TSO150) which covers scripting in detail. If possible, please consider taking this training.

Hope this helps.

Regards,

Vikram

Former Member
0 Kudos

Hi Vikram,

Please help me understand this.


throw new ApplicationException("Hello World");
throw doc.createApplicationException(("field id", "resource id");

I think both the lines above throw an instance of Application Exception class. The latter just binds it to the current document.

I am not able to figure out why an error should occur if Thabiso uses the former statement.

Thanks

Devesh

0 Kudos

Hi Devesh,

I'm not clear under what conditions the reflection error occurred for Kamanga, I can't seem to reproduce it. Any time an application exception is thrown it is recommended that exception is created for the field that is scripted even it is a field data edit or field validation script. To display a message at the top of the document you can throw a new ApplicationException(session, resource id). By passing resource id, the error message will be displayed on the UI based on the user's display language (provided the translation is available for the language).

Hope this helps.

Vikram

0 Kudos

Hi Vikram and Devesh

Thank you guys for the responses, I really appreciate the help.

I have used both the:

throw new ApplicationException("Error Message");

and the:

throw doc.createApplicationException("ui_id","error message");

and both cases I still get the reflection errors.

I have used both these methods in different scripting contexts and I got the desired results.

it is only within this specific context I am getting this reflection errors.

I am not sure why this is happening but I get the feeling that it has something to do with the context I am currently working in.

kind regards,

0 Kudos

Hi Kamanga,

Not sure what's causing the error. I would try clearing the scripting cache and see if that helps.

Regards,

Vikram

Former Member
0 Kudos

Hi Vikram and Kamanga,

I was able to re-create the issue in my system but I am still clueless as to the reason behind such behaviour. I am looking into it and shall update if I find something.

Thanks

Devesh

0 Kudos

Thank you for the help Guys really appreciate it....

regards,

Former Member
0 Kudos

One thing to be aware of is that no matter how you choose to construct your exception in field, field data edit and collection scripts, the attribute is always set to the be the taget field/collection. Have you noticed that? The script designers made things that way. What's going on here is that the exception raised in the Interprer is caught by the Script Manager and rethrown with the script target as the attribute and your raised exception as the exception.

One other thing I would point out is that scripts set to execute on the Collection Member Lifecycle event tend to be poor performers. You can get a faster result if you edit whole collection and chain the errors onto one ChainException. I can only speculate as to why, but I have seen major improvements in complex scripts if I iterate the whole collection, versus implementing a collection memeber lifecycle validate event. This is counter-intuitive, but there it is.

Finally, exceptions raised in Collection Lifecycle Events that interupt the overall save process in the prescence of parent document Lifecycle Validation events can result in partially saved data. I observed this issue a few years back and it may be resolved now. The only member lifecycle event I use is Created, to lock, default, etc.

So, for your particular problem, you may want to rethink your strategy and see if you can get things to work for you bypassing that reflection issue. If you still can't raise the exception on MATERIAL, maybe you can raise it on another field, because another advantage of this approach is that you have full control to raise any error on any field on the Line Items.

Answers (0)