Forum Stats

  • 3,768,656 Users
  • 2,252,827 Discussions
  • 7,874,672 Comments

Discussions

APEX 20.1 Get IG record current values

Rick-Pick
Rick-Pick Member Posts: 81 Bronze Badge
edited Sep 14, 2020 3:15PM in APEX Discussions

I started using javascript extensively in my applications when the interactive grid first came out, but I am far from being expert at it.

I'm using an Interactive Grid master-detail setup and at one point I need to do some calculations based on 4 columns in the detail grid - unit_price, operator ( * or /), quantity and markup (a percentage). When the grid is saved, the calculations are recalculated on the server side. The user can change any of the 4 items and can save at any time. When they save, the total of all the detail items is placed into the selected record in the master grid.

The user may also go to a popup modal dialog which returns the unit_price based on some calculations they do there. This is all working fine, except for one thing - in the javascript DA's which do the calculations, the item values returned by getSelectedRecords() is not giving me the current field values as changed by the user, but is giving me the previous values. For example, if the quantity is set to 10, and the user changes it to 20, the DA which does the calculation still thinks the value is 10.

I can mostly get around this by using "this.triggeringElement.value" in a DA on each of the fields to get the current value when the field is changed, passing this and the name of the element to the calculation function:

var te = "unitCost";

var teVal = this.triggeringElement.value;

calculateCosts( te, teVal );

This does give me the current value of the field as changed, but what I really need is to reliably retrieve the current value of all of the fields at one time, whether changed by the user or not. I'm sure there must be a simple way, but I'm not getting it.

Thanks!

Rick-Pick

Answers

  • Awais Majeed
    Awais Majeed Member Posts: 111 Bronze Badge
    edited Jul 22, 2020 6:29AM
    1. Create a hidden item on the page, e.g. P1_SELECTED
    2. Add a Dynamic Action to the interactive grid region - on Select Change [Interactive Grid]
    3. Add an Action Execute JavaScript Code ("ID" is the column name for the record identifier or whatever data you want to get):
    var i, selectedIds = ":", model = this.data.model; for ( i = 0; i < this.data.selectedRecords.length; i++ ) { selectedIds += model.getValue( this.data.selectedRecords[i], "ID") + ":"; } $s("P1_SELECTED", selectedIds); 
  • Rick-Pick
    Rick-Pick Member Posts: 81 Bronze Badge
    edited Jul 22, 2020 7:02AM

    Hi Awais,

    Thanks, but I'm already getting the key value from the record on Selection Change. The issue is getting the changed values in the record as soon as the user changes them (using dynamic actions on the columns in the grid). This is where the grid model is giving me the old values, pre-change, but I need the new values.

  • Veerendra Patil
    Veerendra Patil Member Posts: 548 Gold Badge
    edited Jul 22, 2020 7:06AM

    Hi,

    Give a static ID for each column you want to access in your IG like C_COL1, C_COL2,..

    then in your DA - Javascript

    var te = "unitCost";

    var teVal = this.triggeringElement.value;

    var col1Val = $v("C_COL1"),

          col2Val = $v("C_COL2");

    calculateCosts( te, teVal );

    Please let me know if this what you want..

    Thanks,

    Veerendra.

  • Rick-Pick
    Rick-Pick Member Posts: 81 Bronze Badge
    edited Jul 22, 2020 8:11AM

    Thanks for your reply Veerendra. The calculation function is working when I pass in the current value as derived using this.triggeringElement.value. The issue is that I need to get the current values of all the fields which may have been changed (or not changed), not only the current one. Using this method I can only get one at a time. Perhaps I should pass "this" (the whole record) into the calculation, but then how do I get the individual field values from it?

  • Veerendra Patil
    Veerendra Patil Member Posts: 548 Gold Badge
    edited Jul 22, 2020 9:08AM

    use $v("C_COL1") to get the value of column 1 of the current ROW in the IG  (C_COL1 is the static id of column 1)

    in your DA

    console.log( $v("C_COL1")   +" --- "+$v("C_COL2") +" --- "+$v("C_COL3") )... this will display col1, col2, col3 values of the record.

    Can you create an example on apex.oracle.com ??

    Thanks,

    Veerendra.

    Rick-Pick
  • Rick-Pick
    Rick-Pick Member Posts: 81 Bronze Badge
    edited Sep 14, 2020 3:15PM

    Veerendra, sorry that I didn't reply earlier. I finally got this working by "chaining" DA's on the relevant fields - two DA's between the four fields if I remember correctly. It has been tested extensively, so I left it at that. Thank you for your advice and I'm sure it will come in handy at some point.