<?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>How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/discussions/f/data/20281/how-to-add-the-data-to-db-within-a-2-tables-1-n-relation</link><description>Hi, 
 When I have to add data within a 1-1 relation between 2 tables, I call the &amp;quot;Write to data store entity&amp;quot; Smart Service to add the new record in the parent table and then, from this component output, I retrieve the generated key Id, to set the Foreign</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79256?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 16:29:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:abd3a5ad-237b-4efd-b98f-d3274c83c955</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Ah that makes sense, it&amp;#39;s pretty cool that it&amp;#39;s still around on environments that have been around for a while!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79252?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 15:37:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6727ae26-1ffe-4759-9a87-3bf0ea5653bb</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Yea, that appears to be the case - definitely an artifact!&amp;nbsp; We&amp;#39;ll be swapping these references out for repeat() and enumerate() tout suite here.&amp;nbsp; Not sure when I might have noticed that if not for this thread!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79248?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 15:20:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3b8919ef-a47b-47cc-a943-a4669c09b27d</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Wow.&amp;nbsp; Talk about legacy.&amp;nbsp; To confirm, in my modern (newer) 20.4 environment, makerange() does not function even as an undocumented function (like try() does), so this must be a legacy remnant from the ancient versions as you mentioned.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79246?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 14:52:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:de1e83d3-8a61-44fa-82b0-7b1e98906e90</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Thanks for confirming Peter.&amp;nbsp; I&amp;nbsp;wasn&amp;#39;t able to find any references in our plugins, but then I did see o&lt;a href="/discussions/f/rules/8991/what-is-makerange"&gt;ne note on the Community here&lt;/a&gt; regarding makerange() in Appian v6, circa 2009 (below) - our environment started way back in the 5.6 days in 2007 (on 20.3 currently).&amp;nbsp; Don&amp;#39;t think that documentation is even posted anymore &lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;makerange() is documented as follows in Version 6:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;makerange() This function will generate a list of values for a given range.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i.e. makerange(4) = {1,2,3,4} ; makerange(4,55) = {55,55,55,55}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79239?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 08:15:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ab26bff8-a4ae-48c2-848c-9ee1c0f1740f</guid><dc:creator>cedric02</dc:creator><description>&lt;p&gt;Thanks a lot for your replies.&lt;br /&gt;It will give me some new ideas for my next processes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79231?ContentTypeID=1</link><pubDate>Thu, 28 Jan 2021 23:35:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:012a52f7-646b-42b6-a052-651679b558d4</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;I don&amp;#39;t see makerange() as a function in my instance of Appian - I would guess that it is probably from a plugin.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79230?ContentTypeID=1</link><pubDate>Thu, 28 Jan 2021 22:57:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b836b832-ed02-4de4-a6aa-0fc4995c9adf</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;I&amp;#39;ll have to admit I never noticed makerange() was not included in Appian Documentation. However, while it is not noted there, Appian does provide a shortcut-entry to select it, and also unlike the undocumented fn!try(), it has a definition listed - the existence of those had put it on my approved list in the past.&amp;nbsp; Might be a good question for Appian Support!&lt;/p&gt;
&lt;p&gt;In the interim, I would agree fn!repeat() would be the better choice based on the documentation reference and same performance/functionality :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/16/makerange1.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/16/makerange2.JPG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79229?ContentTypeID=1</link><pubDate>Thu, 28 Jan 2021 22:38:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e5bd3867-7896-4831-bfb5-0f6d8359287a</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;As an aside, why would you use &amp;quot;makerange&amp;quot; (which seems to be undocumented?) when we can use repeat() which seems to do the same thing you describe?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79228?ContentTypeID=1</link><pubDate>Thu, 28 Jan 2021 22:34:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:91e8f5c6-9d7a-41be-a523-c007394dde02</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;While there are no issues with a!forEach() for this approach, you can also accomplish this with the makerange() function, save into the child FK&amp;#39;s directly, if you are looking for different options.&amp;nbsp; The performance of makerange() is very scalable with 10,000 rows taking only 2-3 ms to complete, with a!forEach() just over 150ms in my testing.&lt;/p&gt;
&lt;p&gt;makerange(count(pv!childCDT),pv!parentCDT.PK)&amp;nbsp; -&amp;gt; Save Into -&amp;gt; pv!childCDT.FK&lt;/p&gt;
&lt;p&gt;Also as an unrelated best practice, I would suggest adding a Terminate event to that end node.&amp;nbsp; For maintenance purposes, if any of the nodes fail and have to be restarted, the process will not complete until the node with error has been manually cancelled, unless a Terminate event is added.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79227?ContentTypeID=1</link><pubDate>Thu, 28 Jan 2021 21:05:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1f527dd1-08be-4513-9e85-fb37e035d8d5</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;This doesn&amp;#39;t seem so bad, to me.&amp;nbsp; It&amp;#39;s the sort of thing that only needs to be done the &amp;quot;first time&amp;quot;, as it were.&amp;nbsp; If you were in some crunch to reduce the total number of nodes to the absolute minimum, then I assume the &amp;quot;save IDs to FK&amp;quot; could be condensed either into the data outputs of &amp;quot;Write Customer&amp;quot;, or the inputs of &amp;quot;Write Contacts&amp;quot;, though either of these approaches would increase the complexity in the target node by a larger factor than what you&amp;#39;d be reducing the process flow by.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79224?ContentTypeID=1</link><pubDate>Thu, 28 Jan 2021 20:51:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:92b59f48-a463-4ff6-94e9-c4d380884333</guid><dc:creator>cedric02</dc:creator><description>&lt;p&gt;Thank you Mike, David,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve created a little example below and in the Script task, I&amp;#39;ve put a little script containing a foreach to set the FKs.&lt;/p&gt;
&lt;p&gt;It works fine, but&amp;nbsp;it couldn&amp;#39;t be simpler ?&lt;br /&gt;I said to myself that maybe&amp;nbsp;there could have a more direct way without a foreach ?&lt;br /&gt;&lt;img alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/16/process-model.JPG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79126?ContentTypeID=1</link><pubDate>Mon, 25 Jan 2021 14:53:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f0d71f9c-5da3-442f-bea8-ea2343691f0b</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Just to confirm, this would be my default approach as well.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Personally, I only use Mutliple WTDS nodes when i&amp;#39;m dealing with already-existing rows and with no question as to whether they already exist and the CDTs i&amp;#39;m dealing with are populated or not.&amp;nbsp; (And even then, really only when there&amp;#39;s a tight crunch on the number of nodes I can use in that particular process flow.)&amp;nbsp; Otherwise it&amp;#39;s always single-WTDS nodes for me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79125?ContentTypeID=1</link><pubDate>Mon, 25 Jan 2021 14:05:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4e3ebb03-98ff-4a3a-96f8-a91f17882cf6</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;Two consecutive write to datastore nodes would be much safer.&amp;nbsp; It ensures that you won&amp;#39;t even start writing contacts with dangling pointers until the object of their pointer is fully built.&amp;nbsp; This is also a good approach because you won&amp;#39;t use Appian to get the primary key of the customer before writing it (which invites race conditions) but rather rely on the DB&amp;#39;s sequencer to get you the next unused ID.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can&amp;#39;t possibly use that to populate the children with the right FK reference if they were written first, but you can extract it from the Stored Values output of the first Write to Datastore node.&amp;nbsp; You can save that as a PV, then throw a script task in between the two Write to Datastore nodes to explicitly plop the FK reference into each of the contacts in a forEach, then write them.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79124?ContentTypeID=1</link><pubDate>Mon, 25 Jan 2021 12:58:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8b0d4854-17bf-4169-b832-ecfff62828df</guid><dc:creator>cedric02</dc:creator><description>&lt;p&gt;Mike, If I take a little&amp;nbsp;example: some contacts are linked to a customer.&lt;/p&gt;
&lt;p&gt;Customer (id,&amp;nbsp;name)&lt;br /&gt;Contact (id,&amp;nbsp;name,&amp;nbsp;fk_customer_id)&lt;/p&gt;
&lt;p&gt;I need to create 3 contacts linked to 1 customer in a Process model.&lt;/p&gt;
&lt;p&gt;Do I need to use a&lt;span&gt;&amp;nbsp;&amp;quot;&lt;/span&gt;&lt;b&gt;Write to Multiple Data Store Entities&lt;/b&gt;&lt;span&gt;&amp;quot; to store the whole data in the DB, or do I need to create two&amp;nbsp;consecutive&amp;nbsp;&amp;quot;&lt;b&gt;Write to Data Store Entities&lt;/b&gt;&amp;quot; smart services (create the customer first, then the contacts) ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add the data to DB within a 2 tables 1-N relation?</title><link>https://community.appian.com/thread/79113?ContentTypeID=1</link><pubDate>Mon, 25 Jan 2021 02:01:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0f05244b-6dc7-4b11-b2dc-63d34ddde8a7</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;It&amp;#39;s fairly simple, all you need to do is set the parent table foreign key value in each member of the child table array when you&amp;#39;re creating them (or just before writing to the DB if necessary).&amp;nbsp; No &amp;quot;looping&amp;quot; per se is needed, though one of the easier ways to populate every member of an array with a certain value can sometimes be using &lt;em&gt;a!forEach()&lt;/em&gt;... but the exact implementation really kinda depends on the subtleties of your exact implementation so far.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>