Insert into Sub Element of Data Schema | Community
Skip to main content
Level 2
November 6, 2019

Insert into Sub Element of Data Schema

  • November 6, 2019
  • 2 replies
  • 9626 views

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

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

2 replies

Jyoti_Yadav
Level 8
November 6, 2019

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.

m-chanAuthor
Level 2
November 6, 2019

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').

Jyoti_Yadav
Level 8
November 7, 2019

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.