<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Updating data in a nested CDT</title><link>https://community.appian.com/discussions/f/data/13729/updating-data-in-a-nested-cdt</link><description>Hi, In a CDT, I have another nested CDT. I would like to update the nested CDT. How can I do this with a!writeToDataStoreEntity while using the main CDT&amp;#39;s primary ID? 
 In my database, it is creating a row in the main CDT rather than the nested CDT. I</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Updating data in a nested CDT</title><link>https://community.appian.com/thread/62305?ContentTypeID=1</link><pubDate>Mon, 05 Nov 2018 15:06:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d7a5c9dd-d3b3-40bb-a6ce-5033f1fbef58</guid><dc:creator>davel001150</dc:creator><description>Some like to use the index() function, I prefer to be very explicit about what I&amp;#39;m doing using the property() function, or at times dot notation.  For instance, myDataType.id or myDataType.name.&lt;br /&gt;
&lt;br /&gt;
You could do index(mainCDT, mainCDT_id, 0).nestedCDT should give you one item of type nestedCDT corresponding to that row.&lt;br /&gt;
Or you could try property(mainCDT, nestedCDT, {}) which should return a list of all the nestedCDT objects inside the list of mainCDT.&lt;br /&gt;
&lt;br /&gt;
To do the database write you&amp;#39;re going to have to make sure you get the row id of mainCDT squared away, then reconstruct all the other data for it, because if you plug in the id for the mainCDT, it should perform a SQL UPDATE statement rather than an INSERT statement.  Any data that doesn&amp;#39;t match what was already on that row for mainCDT gets overwritten with the new stuff.  I believe if you have a brand new nestedCDT type in the definition of the updated row, and it can&amp;#39;t find the ID for the nestedCDT, it will automatically do a SQL INSERT into the nestedCDT table to complete the UPDATE to the mainCDT table.&lt;br /&gt;
&lt;br /&gt;
Another option might be to split the whole thing up into 2 database writes.  Save the nestedCDT to its own table first, use the outputs on the write to datastore node to capture the stored values to get the ID, update the mainCDT row in a script task with the newly captured nestedCDT Id, then perform another write to datastore to update the mainCDT&amp;#39;s nestedCDT id.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>