Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
8 years ago

Create Document program hangs

I create another document upon creating a document with the below code. I wrote this piece of code for onAfterAdd server event under "Document" type. I could not create any document and the UI hangs. Please suggest how to create a new document while creating a document manually and attach to it.
Innovator myInnovator = this.getInnovator(); Item doc = myInnovator.newItem("Document","add"); doc.setProperty("item_number","Hello Document"); doc.setProperty("classification","Design Document"); doc = doc.apply(); CO.Utilities.WriteDebug("testcreate", "document created"); return this;

9 Replies

  • 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 "required", e.g. name? What AML content is returned when you add "doc" to your debugging output?
  • Yes Number is String property and it's not required property as it's said to Sequence. I have a server event to set the number based on the 'classification' property onBeforeAdd event, the following code set the number Innovator inn = this.getInnovator(); string type = this.getProperty("classification", ""); if (type != null && type.Equals("Design Document")) { this.setProperty("item_number", inn.getNextSequence("Design Document")); } else if (type != null && type.Equals("Engineering Document")) { this.setProperty("item_number", inn.getNextSequence("Engineering Document")); } else if (type != null && type.Equals("Supplier Document")) { this.setProperty("item_number", inn.getNextSequence("Supplier Document")); }else{ this.setProperty("item_number", inn.getNextSequence("Default Document")); } 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      
  • I have never seen CO.Utilities. Try to use: CCO.Utilities.WriteDebug(“testcreate”, “document created”);
  • 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;
  • Hello, I believe you're running into an infinite loop. When you create the new Document in your onAfterAdd event, you'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.
    1. Separate out these two Documents into separate ItemTypes: Design Document and Hello Documents (the actual names can change)
    2. Add a check for the classification of the document in your onAfterAdd event like the example below
    Innovator myInnovator = this.getInnovator();
    // Don't create a new Document for documents already created by this kind of event
    if (this.getProperty("classification") == "Design Document") {
    return this;
    }
    // Otherwise, create the new Document as normal
    Item doc = myInnovator.newItem("Document","add");
    doc.setProperty("item_number","Hello Document");
    doc.setProperty("classification","Design Document");
    doc = doc.apply();
    return this;
    Chris
    Christopher Gillis Aras Labs Software Engineer
  • Thank you Chris, finally you pointed out the problem. It works perfectly. My Questions are :
    1. If Suppose I click Save while creating a new Document, this method is getting called and it gets a new sequence number but it's lost
    2. 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 .
    Innovator myInnovator = this.getInnovator(); // Don't create a new Document for documents already created by this kind of event if (this.getProperty("classification") == "Design Document") { return this; }else{ // Otherwise, create the new Document as normal Item doc = myInnovator.newItem("Document","add"); doc.setProperty("item_number",myInnovator.getNextSequence("Design Document")); doc.setProperty("classification","Design Document"); doc.setProperty("name",this.getProperty("name")); doc = doc.apply(); return this; }   Here : myInnovator.getNextSequence("Design Document") 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?   Thanks for your help I was struggling for many days. Am very new to Aras and learning the tool.
  • Hello, Would you be able to offer more details of the use case you'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
    Christopher Gillis Aras Labs Software Engineer
  • Hi,   Use Case 1:
    1. we have no custom document type
    2. create a document
    3. onAfterAdd method we would like to create another document
    4.  link document created in step 2 and step 3
    Use Case 2:
    1. we have custom document types like Design Document & Supplier Document
    2. while we create a Supplier Document there is an event method onAfterAdd
    3. in the onAfterAdd method we would like to create a Design Document
    4. link the document created in step 3 to the document created in Step 2
    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.