Access Tab Field Through JSR

Help
Matt
2012-01-11
2013-03-08
  • Matt
    Matt
    2012-01-11

    Hello everyone,

    I am working on creating a Rule in Adempiere using the rule type: JSR 223 Scripting APIs.

    This rule will be assigned for execution before a record is saved.

    I would like this rule to compare the new value of a certain field with the previous value of that same field. I want to be able to do something if there is a mismatch in the contents of the field.

    The part I don't know how to do is access field values in a tab, but then I think about it, I will be assigning this Rule via Table Script Validator, so will I be able to even access fields of a Tab? This table would be attached to the tab I want to access, if that helps.

    I know I could embed SQL in the JSR Rule and execute that, but I don't think that will give me the value of the field that has not been saved yet, but I think it would give me the old value at least; maybe I need to use SQL just for the old value.

    Any help would be much appreciated.

    P.S. I do not wish to modify the source code of Adempiere in anyway, I would like to work with its capabilities.

    Cheers !

     
  • Matt
    Matt
    2012-01-11

    Now I have learned that Rules can be applied to Table columns and to Tabs (via a Process).

    This means I have direct access to a Tab now. I'm guessing all I need now is the JSR syntax to get field values, etc (if any; I really hope there is).

     
  • Matt
    Matt
    2012-01-11

    Ok, I just experimented with a Commit Message at the Tab Level and that is exactly what I want.

    I would like that dialog box to appear with my custom message, but I don't want that message everytime a save is done, but only when one field has changed its value.

    Is this possible? If so, how?

     
  • Mike Mckay
    Mike Mckay
    2012-01-12

    Hi Matt,

    See http://www.adempiere.com/Script_Callout for some examples.

    You can access the fields by column name using the format

    A_Tab.getValue(<Column name string>)  or
    A_Tab.setValue(<Column name string>)

    You can also test A_Value != A_OldValue if the callout is in the field being changed.

    One approach would be to create a hidden flag field that you set in the callout when the value changes and use the hidden field to determine if you need to display of the Commit Message at the tab level.

    Mike

     
  • Matt
    Matt
    2012-01-12

    Thanks Mike !

    I ended up using a Script Callout as you suggested.

    Assigned it to the column/field I wanted to watch, which took care of watching for change.

    In the JSR Script Callout I used a showConfirmDialog to ask for confirmation.

    To top it all off I used the DB utility and embedded SQL to get the ID of the record and find the value stored for that record, of the field I'm watching.

    I then took that old value and replaced the value the user just put in, if they chose "No" to the confirm box.

    Thanks everyone!!!