<?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>Make a process singleton</title><link>https://community.appian.com/discussions/f/process/10271/make-a-process-singleton</link><description>I have this case where the process must be fired when a specific CDT is created but only once. 
 Is there an easy way to make sure of that? 
 I though of setting up through the start node some kind of expression to be fired when a certain query returns</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45488?ContentTypeID=1</link><pubDate>Wed, 17 May 2017 11:12:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9e163835-37f6-4a90-9a1a-db57fe24fda1</guid><dc:creator>karlg</dc:creator><description>In the end here is what we did and it seems to work perfectly :&lt;br /&gt;
&lt;br /&gt;
1) Start the process in the background the moment it is published (with a delay on the start event set to now())&lt;br /&gt;
2) We hit a receive message node that listens for the event to be triggered&lt;br /&gt;
3) The moment we receive a message we create a task (gets to the create task node)&lt;br /&gt;
--&amp;gt; If other messages are received the process is still locked to the create task node, not creating additional tasks&lt;br /&gt;
4) During the task the user can do some actions which loops back to the task as long as it&amp;amp;#x27;s not completed/finished&lt;br /&gt;
&lt;br /&gt;
When the user finishes the task but right after an event is trigerred (a message is sent to the message node)  the task is recreated correctly and only one task is running at a time.&lt;br /&gt;
&lt;br /&gt;
Another particular thing I like to mention is that the task is an UI of all records created (when a record is created a message is sent to this process thus creating the &amp;quot;singleton task&amp;quot;). Through the UI the user can set a status to &amp;quot;finish&amp;quot; all the said records. Once all records are finished he can then &amp;quot;finish&amp;quot; the task and the process returns to listening for messages on creation of records (and thus the task is not shown anymore since there is no more records to manage at all). The nice thing about this is let&amp;amp;#x27;s say the user has an empty grid under the task and in the UI he&amp;amp;#x27;s about to click on &amp;quot;finish&amp;quot; to terminate the task. Well if &amp;quot;meanwhile&amp;quot; a record was created and his UI didn&amp;amp;#x27;t refreshed when clicking on finish to terminate the UI will submit the form but instead simply refresh the UI and voila the grid displays the newly added record without terminating the task.&lt;br /&gt;
&lt;br /&gt;
This was actually a surprise to me but makes it all perfect for the user experience (because when there&amp;amp;#x27;s a record he can&amp;amp;#x27;t finish the task anymore he needs to manage the said record/records).&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45392?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 19:33:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:72e61db9-34b2-4037-ab6f-899d30a6af1d</guid><dc:creator>sergeiz</dc:creator><description>It is a simple annotation for a CDT field. See &lt;a href="https://docs.appian.com/suite/help/17.1/Database_Schema_Best_Practices.html#optimistic-locking"&gt;docs.appian.com/.../Database_Schema_Best_Practices.html&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45391?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 19:22:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5c98cb99-6ed7-467c-b8aa-320a9323df4e</guid><dc:creator>karlg</dc:creator><description>Thank you for clarifying the &amp;quot;behavior&amp;quot; of the process sergeiz.&lt;br /&gt;
&lt;br /&gt;
I think my last attempt will be the following :&lt;br /&gt;
&lt;br /&gt;
1) Trigger through process to process messages instead of timers (more clear than a polling alternative).&lt;br /&gt;
&lt;br /&gt;
2) When triggered offer a gateway that will query a flag (external object CDT like mentionned through a version annotation). If true proceed, if false end process.&lt;br /&gt;
&lt;br /&gt;
Do you have a quick example of the @Version annotation? Not familiar with the notion.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45386?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 18:51:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:eb496908-3810-487e-940d-804b3f78083b</guid><dc:creator>sergeiz</dc:creator><description>Appian processes are not alike to operation system threads. There is no synchronization mechanism and you have to do it manually on external object like CDT. You can put a check query at your start form to prevent starting a new process every time. But the result for two simultaneous calls can be the same because no transaction yet updated the process. In this case you should have an action that updates the database (@Version annotation), so one update will pass, and others will fail.&lt;br /&gt;
&lt;br /&gt;
Another way I can think of is to use a process with a timer. Any user can click &amp;quot;start&amp;quot; which will update boolean flag in a CDT and this timer can run every few seconds starting another process if the flag is on and using own flag (process variable) to prevent duplication. From user perspective there will be some pause between &amp;quot;start&amp;quot; and process start.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45369?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 13:54:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:355c1b8a-0eb1-457d-9bc0-6441fa400b87</guid><dc:creator>karlg</dc:creator><description>I don&amp;amp;#x27;t like polling solutions but I think in my case I don&amp;amp;#x27;t have much of a choice.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45368?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 13:50:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:340b057c-b1da-42ae-9765-4367ff629c35</guid><dc:creator>karlg</dc:creator><description>To have only one task assigned to the group so it won&amp;amp;#x27;t create noise.  One task that leads to one dashboard to handle all inventory when there is one or more inventory. The dashboard can lead to various options and one that &amp;quot;finishes&amp;quot; the inventory. At that point we have no more inventory so the task closes and no more access to the dashboard because there&amp;amp;#x27;s nothing to manage.&lt;br /&gt;
&lt;br /&gt;
What you are suggesting is interesting ;&lt;br /&gt;
&lt;br /&gt;
Keep process XYZ as a system process running at all times, but provide a &amp;quot;check&amp;quot; through a timer on the database. When having more than one &amp;quot;inventory&amp;quot; that poped ; create task (and thus assign to group and give access to dashboard). Within task if all inventory was &amp;quot;finished/processed/whatever&amp;quot; complete task and return to &amp;quot;listening&amp;quot; to the lock.&lt;br /&gt;
&lt;br /&gt;
I think this would actually be good Josh!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45366?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 13:43:25 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7795d91e-ed4f-42e4-be5d-ab63ba1deaa7</guid><dc:creator>Josh</dc:creator><description>Why is it a requirement to only have one process instance? Why not just launch the process, check for the lock in the database, continue with the process if there is no lock, but terminate the process instance if there is a lock?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45364?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 13:12:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5f00544f-2724-4843-a109-5908717670a9</guid><dc:creator>karlg</dc:creator><description>Oh my bad, let&amp;amp;#x27;s say we include a version annotation wouldn&amp;amp;#x27;t it be the same problem as the flag would be within the database instead? Let&amp;amp;#x27;s go with : &lt;br /&gt;
&lt;br /&gt;
Process ABC that creates the inventory in the database.&lt;br /&gt;
&lt;br /&gt;
Process XYZ that must be a singleton, created when no other XYZ is present and when we have at least one inventory that was created.&lt;br /&gt;
&lt;br /&gt;
Within ABC, after creating/writing in the database the inventory cdt, we put a gateway based of the attribute version of the CDT that indicates if we fire the process XYZ or not? &lt;br /&gt;
&lt;br /&gt;
We tried with a flag within the database (a simple table with a boolean) which would be the same technically and it created two XYZ process instances. Unless my understanding is wrong of what you are proposing.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45361?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 12:52:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:21e4eea7-c2f1-4b9d-9906-644bd7ce8248</guid><dc:creator>nathan.schmitz</dc:creator><description>In the solution I&amp;amp;#x27;m proposing we are locking the data, not the process.  When designing the inventory CDT, we include a version attribute that uses the @Version annotation.  This will ensure that the data that we are writing back to the database is the same as the version when we started the process thus ensuring data integrity.   Does this make sense?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45360?ContentTypeID=1</link><pubDate>Wed, 10 May 2017 12:17:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2f13bc99-26b9-4a14-92fd-cb485fec1556</guid><dc:creator>karlg</dc:creator><description>It does nathan.schmitz and thank you for your response and time.&lt;br /&gt;
&lt;br /&gt;
The only thing I needed to specify in my case is that inventory can be asked from anyone at any time for example. The second an inventory is created through an action like you mentioned we need to start the process. But that is true for any inventory from anyone at any time. So let&amp;amp;#x27;s say 2 users asks for anything (even the same thing) from inventory, at the same time, I still need to handle this case and start off only once a specific process.&lt;br /&gt;
&lt;br /&gt;
As mentionned if your fast enough (within the same second) it will trigger more than one process instance even though I&amp;amp;#x27;ve provided a gateway mentionning if more than one instance of active process of XYZ do nothing.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45334?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 20:27:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:aadaa743-0e22-4b53-89c7-3bc6a7545fac</guid><dc:creator>nathan.schmitz</dc:creator><description>If I understand your use case correctly, I think you&amp;amp;#x27;d want to use records and you would want to use either entity backed or expression backed records.  Using your example, you could create a record of type &amp;quot;inventory&amp;quot; that referenced the CDT/data store entity of type Inventory.  You could then take actions on these inventory items by using related actions.   Creating a new inventory item would probably come from an action that would use the Write to Datastore&amp;quot; service to add a new item to the inventory record list.  To mitigate your duplication concern, I&amp;amp;#x27;d recommend flagging to the user that there is a similar inventory item already created and allowing them to remove or merge the new added inventory item with the existing one.   Does this make sense?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45332?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 17:45:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:564cff51-12be-48ec-9a68-4ec4a775ca99</guid><dc:creator>karlg</dc:creator><description>Well we tried with a numprocessesforprocessmodelforstatus and if your fast enough it will create 2 same process sadly, we used the following gateway &amp;amp;#x60;&lt;br /&gt;
&lt;br /&gt;
IF (=numprocessesforprocessmodelforstatus(0000, &amp;quot;active&amp;quot;, false) &amp;gt; 0) THEN GOTO END NODE&lt;br /&gt;
ELSE CREATE PROCESS XYZ with dashboard/task&lt;br /&gt;
&lt;br /&gt;
I think the way to go is through SQL perhaps and keep a flag within a table of some sort? Through an insert the first thread would lock? running out of ideas.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45331?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 17:18:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1f5458a1-a22d-49a3-b288-37953779e0c9</guid><dc:creator>karlg</dc:creator><description>Yeah with context it might help, I&amp;amp;#x27;ll give a quick example :&lt;br /&gt;
&lt;br /&gt;
Let&amp;amp;#x27;s say the client wants to manage inventory. So through an existing action/form or some sort we can create inventory (your CDT). At one point the client wants to manage all the inventory rapidly under one task and one interface only. So when a CDT is created automatically we create this task that links to a dashboard of all inventory. No inventory? No task/dashboard needed. One or more inventory? One dashboard accessible through the one task link. They don&amp;amp;#x27;t want one task per inventory item.&lt;br /&gt;
&lt;br /&gt;
So we thought about using numprocessesforprocessmodelforstatus() function as a gateway when the inventory is created to lunch a new process that creates the task / dashboard interface but afraid of duplicates of the process as we truly just want one max.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45330?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 15:28:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4a6645ac-c3ab-491a-94a0-b3df02ce2b3c</guid><dc:creator>Jim Schweitzer</dc:creator><description>Maybe look at the @version annotation if you&amp;amp;#x27;re using a database? I think this would only be helpful if you know what the PK is going to be, and are updating an existing row.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45329?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 15:21:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0eb8d26b-9b01-4040-837d-cd7a5a629982</guid><dc:creator>Mike Schmitt</dc:creator><description>Can you tell us a little bit more about your use case need to have only one process instance?  And do you mean a CDT is created or a new row of data associated to that CDT?  Because off the top of my head I&amp;amp;#x27;m not sure how to have a process monitor for creation of a particular CDT if the CDT in question doesn&amp;amp;#x27;t exist yet - that&amp;amp;#x27;s a big contradiction.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Make a process singleton</title><link>https://community.appian.com/thread/45328?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 15:20:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:130b13c6-58a8-49fa-bded-51b17d7f14a7</guid><dc:creator>karlg</dc:creator><description>Worst case we can adapt the solution so that the process responsible of creating the CDT triggers the other process. &lt;br /&gt;
&lt;br /&gt;
But what &amp;quot;gateway&amp;quot; might I provide to make sure the process is started only once? Let&amp;amp;#x27;s say this other process (sub process node) creates a task at first, I could always check if the task already exists and if it does don&amp;amp;#x27;t start it. &lt;br /&gt;
&lt;br /&gt;
But what will happen if 2 users at the same time does the same operation I wonder? I think there&amp;amp;#x27;s still a risk of having more than one instance.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>