Expand my Community achievements bar.

Insert into Sub Element of Data Schema

Avatar

Level 2

Hi,

I am trying to insert data into an attribute that's under a sub element.

Here is the part of the script where I define what to insert:

  var event =

    <exampleEvent

      xtkschema = "exp:exampleEvent"

      _operation = "insert"

      deliveryTitle = {deliveryTitle}

    />

Here is an example of my data schema:

  <element name="exampleEvent">

    <element name="subExamples">

      <attribute label="Delivery Title" name="deliveryTitle" type="string"/>

    </element>

  </element>

If I were to take the 'deliveryTitle' attribute out of the subelement 'subExamples', then I am able to see data populate in the 'deliveryTitle' column. However, once I place the 'deliveryTitle' attribute into the sub element, data no longer populates.

Please advise.

Thanks,

Michelle

3 Replies

Avatar

Community Advisor

Hi,

Hi,

Add data like you have defined your XML:

xtk.session.Write(

<exampleEvent  xtkschema = "exp:exampleEvent"    _operation = "insert">

< subExamples deliveryTitle = {deliveryTitle}/>

</exampleEvent> );

Your data will be saved in correct field.

Thanks.

Avatar

Level 2

Thanks jyotiy - I tried your solution above and got this error:

JST-310000 Error while compiling script 'exp:exampleEvent.js' line 51: invalid XML name (line=' < subExamples deliveryTitle = {deliveryTitle}/>\n' token=' subExamples deliveryTitle = {deliveryTitle}/>\n').

Avatar

Community Advisor

Hi,

Can you share your script you have written.

Is your subelement name correctly defined? Also have you defined deliveryTitle variable.

In order to analyse what is wrong you need to share table structure and script you have written.

Code which I have provided is correct.

Thanks.