Credit for figuring these out/discovering them goes to Perry. I find myself referring to them in a training binder I got from last year’s NY Training Summit and figured it would be easier to just get them up on the web so I don’t have to go hunting for that binder every time. The following code works for Classic.
Scenario 1: Get the Value of a Subform Field
This code is for use within the subform, e.g. if you want to default the value of one field based on the value of another on the same subform.
self object is being used here. This is the subform object as distinguished from the parent form object. The parameter
currentRowXML then further narrows it down to the current record/row on the subform that you are concerned with.
Scenario 2: Set the Value of a Subform Field
Again, for use within a subform, this code can be used to set the value of a field in the same subform, e.g. when you want the On Change event to auto-populate a field.
If you are checking a checkbox, use this code:
this.form.'column_name'.checked = true;
Note that in this code, you do keep the single quotes in the code for it to work properly. All you change is the
Scenario 3: Get the Value of a Parent Form Field
With this code, you can get the value of a field in the parent form based on an action in the subform.
window.parent is the only difference from the code you would use on the parent form. This is what allows your code to ‘jump up out of the subform’.
Scenario 4: Set the Value of a Parent Form Field
Maybe you figured it out by now but you can use the same small change to set values on the parent form from the subform.
Scenario 5: Trigger an Alert from the Subform
Alerts are useful in guiding user activity and you can trigger them from subforms. Similar to the last two, the trick is moving back up the DOM to the parent form to trigger it.
It is possible to go the other way and get and set values on subform records from the parent form, however, it becomes a much more complex problem that requires very specific solutions for very specific challenges. That is because of the One-to-Many relationship that the subforms have with the parent form. For these types of situations, you will probably be targeting the subform itself and then looping through each record to get or set values.