Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Using string to designate a subform for the instanceManager

Avatar

Level 7

var propOptSubformID     = "8011"

var propSubformName     = Concat("SubformPropOption",propOptSubformID,".instanceManager")      //since instanceManager is object

$.resolveNode(propSubformName).setInstances(1)

I get:

Capture.JPG

I can't seem to find a way to use the instanceManager and successfully reference a subform using a string. Any ideas?

I want to avoid using conditional statements or switch if possible. I have 35 different subforms eachl with 0 instances. I want to identify one of the subforms using a variable (string) and make it exist. There has to be a way to do this, right?

I may have to name all the subforms the same and use an index--but I would like to avoid that, Or, I suppose I could loop through the siblings and compare my string to the subform name--but I think this might end up having the same problem. It would be really good to know how to do it with a string and the instanceManager..

Thanks,

Stephen

PS, I also tried

var propSubformName     = Concat("SubformPropOption",propOptSubformID,".instanceManager.setInstances(1)")

$.resolveNode(propSubformName)

and...  Nothing happens? No error and no subform either?

4 Replies

Avatar

Level 10

Concat("SubformPropOption[",propOptSubformID,"].instanceManager")

Avatar

Level 7

Thanks Robert,

I might be missing something--I've never seen square brackets used in the way you suggest. Am I missing something?

The subform doesn't have an index[propOptSubformID]  It would have an index[0] when it actually does exist. This isn't really an index problem. That would be easy and I think I may have to go that way (i.e. name them alll the same and reference them by index) if I can't reference the object.instanceManager and use its method setInstances() with a string.

This might be a clue: the error message referred to setInstances() as a property--it is a method(). If it had recognized it as a method, then it the error would have said that the object doesen't have a method setInstances(). Also, it represented the ("1") as a string when it an integer parameter for setInstances().

Stephen

Avatar

Level 10

Hi,

the instanceManager property cannot be part of a SOM expression, that's why your script fails.

Use this script instead:

var propOptSubformID     = "8011"

xfa.resolveNode("SubformPropOption" + propOptSubformID).instanceManager.setInstances("1");

Avatar

Level 7

Hi Radzmar,

I ran your JS script (added a semicolon at the end of 1st line) and got:

Exception in line 2 of function top_level, script XFA:form1[0]:SubformBody[0]:SubformLocation[0]:SubformPropCrDb[0]:DdlPropCreditDesc[0]:exit

Also, tried the same without the quotes ("1") with same result

Any idea whats going on?

Message was edited by: kingphysh