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.

Assigning values to repeating subforms using a script

Avatar

Level 7

I am using a script to add values to a repeating subform. Below is a simple example. In the real script I would use a loop to do the inserts.

//declare XML structure

String hrxdproot = /process_data/hrxfaform/object/data/xdp/datasets/data/form1";

//assigning repeating subform number

int i = 1;

//assign a value to the first repeating subform

patExecContext.setProcessDataStringValue(hrxdproot + "/Details[" + i +"]/employee_name", "Aditya");

However, the error I get is

"Target exception: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. "

I also tried to use a SetValue module to perform the same function and got the above error.

/process_data/hrxfaform/object/data/xdp/datasets/data/form1/Details[1]/employee_name = "Aditya"

Finally, I manually merged a sample xml (with 2 instances of the repeating subform) with the pdf and it worked fine. So I don't think there is a problem in the XML.

Can someone please help...

Aditya

9 Replies

Avatar

Level 10

"patExecContext.setProcessDataStringValue(hrxdproot + "/Details[" + i +"]/employee_name", "Aditya");"

The above will definitely not work. The first parameter of the setProcessDataStringValue needs to be the name of the variable you want to set. It needs to be in the format setProcessDataStringValue('/process_data/@myStringVar', 'myValue').

If you wanted to set a string variable or document variable with xml content , you would have to create your xml structure using standard java DOM functions first.

Once you have your xml structure build properly, then you can use the setProcessDataStringValue or setProcessDataDocumentValue functions to set the content of your variable.

Jasmin

Avatar

Level 7

Jasmin - Thank you for replying.

"The above will definitely not work. The first parameter of the setProcessDataStringValue needs to be the name of the variable you want to set. It needs to be in the format setProcessDataStringValue('/process_data/@myStringVar', 'myValue')."

You are saying that the above statement will set the value of myValue to @myStringVar ? or vice versa ?

"If you wanted to set a string variable or document variable with xml content , you would have to create your xml structure using standard java DOM functions first."

I am tryng to assign a value to a field in the XML structure so why would I need to build the structure ? The variable is already an XML structure.

Aditya

Avatar

Level 10

"You are saying that the above statement will set the value of myValue to @myStringVar ? or vice versa ?"

The statement will set the value of variable myStrinvVar to myValue. Please see http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402587 for more information on the patExecContext object.

"I am trying to assign a value to a field in the XML structure so why would I need to build the structure ? The variable is already an XML structure."

I though you needed to create some nodes in you XML? If not then you can just a SetValue to set the value of the specific node. You won't be able to use patExecContext methods to set a particular node of the xml. This will set the entire variable's content.

Jasmin

Avatar

Level 7

Like I mentioned in the initial thread

"I also tried to use a SetValue module to perform the same function and got the above error.

/process_data/hrxfaform/object/data/xdp/datasets/data/form1/Details[1]/employee_ name = "Aditya"

I tried your suggestion and I unable to add a value to a node in the repeating subform. I get the same error.

Aditya

Avatar

Level 7

Something I'd like to add.


The XML structure has no data in it. I am simply adding data to pre-fill multiple instances of the subform.

I don't know if this helps.


Aditya

Avatar

Level 10

But the question is wether or not you're going to dynamically add nodes to your structure. Even if the schema permits to have multiple nodes under a specific section, it's hard to use xPath to do that. For example if you have a structure like the following:

<Root>

  <Node1/>

</Root>

and use the following xPath /process_data/xmlvar/Root/Node1/Child1, you're going to end up with the following:

<Root>

  <Node1>

      <Child1>

   </Node1>

</Root>

Now if you try to add another node under child node with a similar xPath /process_data/xmlvar/Root/Node1/Child2, you're going to end up with the following:

<Root>

  <Node1>

      <Child2>

   </Node1>

</Root>

It won't append the node, it will replace everything under Node 1.

So if this is what you're trying to do (add multiple children nodes), then you would have to create the xml structure using standard DOM objects within a custom component or the script service and the set the resulted xml to an xml variable.

I hope this clears thigns up.

Jasmin

Avatar

Level 2

Hi Jasmin, do you have an example of this??

Thx

Avatar

Former Community Member

Hi Kris,

I am facing some similer issue. Did you get a solution of it.

Please help in resolving it.

Rohan