<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/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>Create Document program hangs</title><link>https://www.aras.com/community/f/development/3879/create-document-program-hangs</link><description>I create another document upon creating a document with the below code. I wrote this piece of code for onAfterAdd server event under &amp;quot;Document&amp;quot; type.

I could not create any document and the UI hangs. Please suggest how to create a new document while</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1963?ContentTypeID=1</link><pubDate>Fri, 10 Aug 2018 02:05:08 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:db17a5f5-6554-4921-b940-bd628fe6c794</guid><dc:creator>Former Member</dc:creator><description>Hi,

&amp;nbsp;

Use Case 1:
&lt;ol&gt;
 	&lt;li&gt;we have no custom document type&lt;/li&gt;
 	&lt;li&gt;create a document&lt;/li&gt;
 	&lt;li&gt;onAfterAdd method we would like to create another document&lt;/li&gt;
 	&lt;li&gt; link document created in step 2 and step 3&lt;/li&gt;
&lt;/ol&gt;
Use Case 2:
&lt;ol&gt;
 	&lt;li&gt;we have custom document types like Design Document &amp;amp; Supplier Document&lt;/li&gt;
 	&lt;li&gt;while we create a Supplier Document there is an event method onAfterAdd&lt;/li&gt;
 	&lt;li&gt;in the onAfterAdd method we would like to create a Design Document&lt;/li&gt;
 	&lt;li&gt;link the document created in step 3 to the document created in Step 2&lt;/li&gt;
&lt;/ol&gt;
I think I explained the requirement. Also would like to know if we can write a scheduler in Aras to run at 1 hour interval to load documents from a remote server.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1962?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 13:05:37 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:f93dafe8-ef00-4928-838e-6ade363db43e</guid><dc:creator>Christopher Gillis</dc:creator><description>Hello,

Would you be able to offer more details of the use case you&amp;#39;re trying to accomplish? What is the second document that is created intended to represent? It may be possible to achieve a similar result through other means that avoids the possibility of this infinite loop entirely.

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1961?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 12:45:15 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:9dbb1285-3349-4b11-8d4a-5662b520bb5d</guid><dc:creator>Former Member</dc:creator><description>Thank you Chris, finally you pointed out the problem. It works perfectly. My Questions are :
&lt;ol&gt;
 	&lt;li&gt;If Suppose I click Save while creating a new Document, this method is getting called and it gets a new sequence number but it&amp;#39;s lost&lt;/li&gt;
 	&lt;li&gt;Say I create Document and onAfterAdd method is called and the sequence is also called but the document is not added. Again when I click save and close , a new sequence number is called .&lt;/li&gt;
&lt;/ol&gt;
Innovator myInnovator = this.getInnovator();
// Don&amp;#39;t create a new Document for documents already created by this kind of event
if (this.getProperty(&amp;quot;classification&amp;quot;) == &amp;quot;Design Document&amp;quot;) {
return this;
}else{
// Otherwise, create the new Document as normal
Item doc = myInnovator.newItem(&amp;quot;Document&amp;quot;,&amp;quot;add&amp;quot;);
doc.setProperty(&amp;quot;item_number&amp;quot;,myInnovator.getNextSequence(&amp;quot;Design Document&amp;quot;));
doc.setProperty(&amp;quot;classification&amp;quot;,&amp;quot;Design Document&amp;quot;);
doc.setProperty(&amp;quot;name&amp;quot;,this.getProperty(&amp;quot;name&amp;quot;));
doc = doc.apply();
return this;
}

&amp;nbsp;

Here : myInnovator.getNextSequence(&amp;quot;Design Document&amp;quot;) is called even when I click Save button and that number is lost, so if I have a document with 1001 and the next document is created with 1003.

2. How to create an another Design Document only once. Any logic here?. I know you said we should not create the same document type. But what if I really need to create another Design Document?

&amp;nbsp;

Thanks for your help I was struggling for many days. Am very new to Aras and learning the tool.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1960?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 12:02:21 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:f236abca-b768-4bfd-a807-b3276229576c</guid><dc:creator>Christopher Gillis</dc:creator><description>Hello,

I believe you&amp;#39;re running into an infinite loop. When you create the new Document in your onAfterAdd event, you&amp;#39;re also triggering another onAfterAdd for that new Document which in turn is creating another Document and triggering another onAfterAdd, etc.

There are two ways I can see around this.
&lt;ol&gt;
 	&lt;li&gt;Separate out these two Documents into separate ItemTypes: Design Document and Hello Documents (the actual names can change)&lt;/li&gt;
 	&lt;li&gt;Add a check for the classification of the document in your onAfterAdd event like the example below&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Innovator myInnovator = this.getInnovator();
// Don&amp;#039;t create a new Document for documents already created by this kind of event
if (this.getProperty(&amp;quot;classification&amp;quot;) == &amp;quot;Design Document&amp;quot;) {
return this;
}
// Otherwise, create the new Document as normal
Item doc = myInnovator.newItem(&amp;quot;Document&amp;quot;,&amp;quot;add&amp;quot;);
doc.setProperty(&amp;quot;item_number&amp;quot;,&amp;quot;Hello Document&amp;quot;);
doc.setProperty(&amp;quot;classification&amp;quot;,&amp;quot;Design Document&amp;quot;);
doc = doc.apply();
return this;&lt;/code&gt;&lt;/pre&gt;


Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1959?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 06:14:26 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:438a8aa9-6ce5-4e5a-ba69-7b1f01ef8d8a</guid><dc:creator>Former Member</dc:creator><description>Ya I fixed that long back.

Innovator myInnovator = this.getInnovator();
Item doc = myInnovator.newItem(“Document”,”add”);
doc.setProperty(“item_number”,”Hello Document”);
doc.setProperty(“classification”,”Design Document”);
doc = doc.apply();
CCO.Utilities.WriteDebug(“testcreate”, “document created”);
return this;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1958?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 06:12:52 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:c4f70b3c-a207-4483-bfab-2147e18f462f</guid><dc:creator>AngelaIp</dc:creator><description>I have never seen CO.Utilities. Try to use:
CCO.Utilities.WriteDebug(“testcreate”, “document created”);&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1957?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 06:00:56 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:fd10538d-8e60-45d8-93af-6668f67e2acb</guid><dc:creator>Former Member</dc:creator><description>Yes Number is String property and it&amp;#39;s not required property as it&amp;#39;s said to Sequence. I have a server event to set the number based on the &amp;#39;classification&amp;#39; property onBeforeAdd event, the following code set the number

Innovator inn = this.getInnovator();

string type = this.getProperty(&amp;quot;classification&amp;quot;, &amp;quot;&amp;quot;);

if (type != null &amp;amp;&amp;amp; type.Equals(&amp;quot;Design Document&amp;quot;)) {
this.setProperty(&amp;quot;item_number&amp;quot;, inn.getNextSequence(&amp;quot;Design Document&amp;quot;));
} else if (type != null &amp;amp;&amp;amp; type.Equals(&amp;quot;Engineering Document&amp;quot;)) {
this.setProperty(&amp;quot;item_number&amp;quot;, inn.getNextSequence(&amp;quot;Engineering Document&amp;quot;));
} else if (type != null &amp;amp;&amp;amp; type.Equals(&amp;quot;Supplier Document&amp;quot;)) {
this.setProperty(&amp;quot;item_number&amp;quot;, inn.getNextSequence(&amp;quot;Supplier Document&amp;quot;));
}else{
this.setProperty(&amp;quot;item_number&amp;quot;, inn.getNextSequence(&amp;quot;Default Document&amp;quot;));
}
return this;

there is no required property. and when I click new document and save it, a document number is set and the document is added.

AML document? I could not see an debug log. and the UI is hanging

&amp;nbsp;

&amp;nbsp;

&amp;nbsp;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1956?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 04:31:25 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:9eafae71-b678-495b-b824-7e8d767a9b05</guid><dc:creator>AngelaIp</dc:creator><description>Is your item_number really a string property or do you use a sequence as you have mentioned in other forum posts?
Do you have certain Document properties that are &amp;quot;required&amp;quot;, e.g. name?

What AML content is returned when you add &amp;quot;doc&amp;quot; to your debugging output?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Create Document program hangs</title><link>https://www.aras.com/community/thread/1955?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 04:04:33 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:79127968-4856-4eff-9f1e-e9ed2628223f</guid><dc:creator>Former Member</dc:creator><description>Can anyone help me to fix this small issue?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>