Reset a single field in repeated Subform...I cannot seem to reference it.... | Community
Skip to main content
New Participant
January 21, 2022
Solved

Reset a single field in repeated Subform...I cannot seem to reference it....

  • January 21, 2022
  • 3 replies
  • 1514 views

Good morning

 

I am trying to reset ONE field in a repeating subform.  I don't want to hide the instances of the subform for this action, or re-set the entire form.  

The field I wish to reset is form1.Main.sfOMKT.Table1.Row3.sfFigs.numFigures and sfOMKT is the repeating subform which it lives in. 

 

Obviously this works great for the first instance: xfa.host.resetData("form1.Main.sfOMKT.Table1.Row3.sfFigs.numFigures");

But no matter how much I read I cannot grasp the referencing thing...

 

Would anyone be able to help?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mayank_Tiwari

I am assuming by resetting the field, you want to set its value to null or empty.

Then try this script.

 

var subforms = this.resolveNodes(" form1.Main.sfOMKT[*]");

for(var i =0; i<subforms.length;i++)
{
subforms.item(i).Table1.Row3.sfFigs.numFigures.rawValue = ""; }

3 replies

radzmar
New Participant
January 23, 2022

Hi,

 

you can use the resolveNodes() method, to reference multiple instances in an object.

Here's an example. You're creating a node list for all instances of sf0MKT named oSubforms. 

Then you're using a for loop to process every node in the list.

var oSubfoms = form1.Main.resolveNodes("sfOMKT[*]),
    i = 0;

for (i; i < oSubfoms.length; i += 1) {
    var oNode = oSubform.item(i);
    oNode.Table1.Row3.sfFigs.numFigures.rawValue = null;
}
New Participant
January 23, 2022

Thank you so much!!!  I don't know where I would be without this forum.

For a self starter I have made some pretty decent bespoke forms for my organisation largely thanks to the help of you guys here when I hit a roadblock.

 

I really want to understand how you know to use stuff like this 

for (i; i < oSubfoms.length; i += 1) {

Can you recommend anything for a total beginner for JS?  Course, reading material?  I read a LOT of stuff and sometimes can work it out for myself, but I lack the basic knowledge so I don't think I will ever progress until I get that base....

 

New Participant
January 24, 2022
MHWinter
New Participant
January 21, 2022

You need to specify the instance's index of the repeating subform to target. 

so if the action is triggered by an event linked to a cell in the same row as the field to be reset,you could do something like this:

// determine the index of the targeted instance of the repeating form

var TargetIndex = this.parent.parent.parent.index; 

// create the string representing the SOM of the targeted field

var TargetCell = "form1.Main.sfOMKT["+TargetIndex+"].Table1.Row3.sfFigs.numFigures";

// reset the value of the targeted cell

xfa.host.resetData(TargetCell);

New Participant
January 24, 2022

Thank you so much @mhwinter !!

Mayank_Tiwari
Mayank_TiwariAccepted solution
Employee
January 21, 2022

I am assuming by resetting the field, you want to set its value to null or empty.

Then try this script.

 

var subforms = this.resolveNodes(" form1.Main.sfOMKT[*]");

for(var i =0; i<subforms.length;i++)
{
subforms.item(i).Table1.Row3.sfFigs.numFigures.rawValue = ""; }
New Participant
January 23, 2022

Works beautifully.  Again you save me 🙂