Set dispositions to "N/A" on all affected documents with action set to "Revise"

I added this method under the "Server Events" tab, client-side, C# but it does not work. What is incorrect?

if (this.getProperty("action") == "Revise" && this.getProperty("item_type") == "Document") {
    this.setProperty("dispo_assemble","N/A");
    this.setProperty("dispo_repairs","N/A");
    this.setProperty("dispo_stock_kit","N/A");
    this.setProperty("dispo_supplier_stock","N/A");
    this.setProperty("dispo_wip","N/A");    
}
return this;

Parents
  • We currently have an affected item server event that populates all four of the dispositions when the affected item action is “Release”. This happens when the user adds the affected items and then saves the CN. The event is set to “onBeforeAdd”. This is the script:

     

    if (this.getProperty("action") == "Release") {

                    this.setProperty("dispo_assemble","N/A");

                    this.setProperty("dispo_repairs","N/A");

                    this.setProperty("dispo_stock_kit","N/A");

                    this.setProperty("dispo_supplier_stock","N/A");

                    this.setProperty("dispo_wip","N/A"); 

    }

    return this;

     

    I need to add something similar for affected items that are set to the action “Revise” but only for item type “Document” (not part). The item_type “Document” is not displayed until after the save occurs. I created the following script but it does not work. The item_type property “Document” is not populated until after the save so I don’t know which event to use. I think I have the script correct but not sure.

     

    if (this.getProperty("action") == "Revise" && this.getProperty("item_type") == "Document") {

                    this.setProperty("dispo_assemble","N/A");

                    this.setProperty("dispo_repairs","N/A");

                    this.setProperty("dispo_stock_kit","N/A");

                    this.setProperty("dispo_supplier_stock","N/A");

                    this.setProperty("dispo_wip","N/A"); 

    }

    return this;

  • Hello,

    The type of item a request affects can be found in the type attribute of the request as you can see below.

    <AML>
        <Item type="Document" action="add">
             <!-- Property data would be here -->
        </Item>
    </AML>

    You can access this data most easily by using the getType() function, so your if statement could be easily modified to instead check for the type of item like so.

    if (this.getProperty("action") == "Revise" && this.getType() == "Document")

    Chris


    Christopher Gillis

    Aras Labs Software Engineer

Reply
  • Hello,

    The type of item a request affects can be found in the type attribute of the request as you can see below.

    <AML>
        <Item type="Document" action="add">
             <!-- Property data would be here -->
        </Item>
    </AML>

    You can access this data most easily by using the getType() function, so your if statement could be easily modified to instead check for the type of item like so.

    if (this.getProperty("action") == "Revise" && this.getType() == "Document")

    Chris


    Christopher Gillis

    Aras Labs Software Engineer

Children
  • Chris,

    Not working.

    When we create a new affected item relationship we select "Revise" from the "Action" drop-down field. Then we search for the document number which displays in the affected item row. However, the item type (Document) does not display until we save. I have the following script set to the CN affected item server event "onBeforeAdd". The only data displayed at that time is the action and the document number. Is there a way to get the type from the document number (affected_id) displayed?

    if (this.getProperty("action") == "Revise" && this.getType() == "Document"){
        this.setProperty("dispo_assemble","N/A");
        this.setProperty("dispo_repairs","N/A");
        this.setProperty("dispo_stock_kit","N/A");
        this.setProperty("dispo_supplier_stock","N/A");
        this.setProperty("dispo_wip","N/A");    
    }
    return this;

  • Hello,

    Ah. This is an Affected Item. Affected Items are pretty unique in terms of their data model. It'll likely take a little more work to get the ItemType of the affected item you've selected.

    The first step is to establish what data you have access to inside of this in your server event. You can check this a few ways either by turning on logs or by debugging into the methodthis is going to store the request that's being sent to the server to add your affected item. As an example, let's work under the assumption that you're only given the bare minimum of information.

    <Item type="Affected Item" action="add">
         <action>Revise</action>
         <affected_id keyed_name="My Document">BC5157C0BB844887817719973C32C5AD</affected_id>
    </Item>

    From this request, we don't know what the ItemType of the affected item is; we just know the ID. To work around this, we can do a query to see if there's a Document in the system that has this ID. If we get a result, we know that the affected item is a Document and we should set the default values for the properties. If we get back nothing, the affected item is not a Document, and we should not set the default values for those properties.

    Innovator inn = this.getInnovator();
    Item affectedDocument = inn.newItem("Document", "get");
    affectedDocument.setID(this.getProperty("affected_id"));
    affectedDocument = affectedDocument.apply();
    if (affectedDocument.isEmpty())
    {
         // The affected item is a Document
    }
    else
    {
         // The affected item is not a Document
    }

    Chris

  • Does this look correct? I couldn't get it to work. I have it on the onBeforeAdd affected item server event.

    Innovator inn = this.getInnovator();
    Item affectedDocument = inn.newItem("Document", "get");
    affectedDocument.setID(this.getProperty("affected_id"));
    affectedDocument = affectedDocument.apply();
    if (affectedDocument.isEmpty())
    {
    // The affected item is a Document
    if (this.getProperty("action") == "Revise"){
           this.setProperty("dispo_assemble","N/A");
        this.setProperty("dispo_repairs","N/A");
        this.setProperty("dispo_stock_kit","N/A");
        this.setProperty("dispo_supplier_stock","N/A");
        this.setProperty("dispo_wip","N/A");    
    }
    }
    return this;

  • Hello,

    Could you clarify your exact use case? Do these dispo_ properties exist on the Affected Item ItemType or on the Document ItemType? 

    Chris

  • Chris,

    On the Affected Item ItemType. The "N/A" is one of the choices in the disposition drop-down fields for each affected item row. These columns are meant for the engineer to state the part dispositions so for documents, we always have to enter "N/A" when the action is a release or a revise. The release script already works because we add N/A to both the parts and the documents. So if the action is 'revise" that script enters N/A in both the parts and documents. i am now trying to do the same thing for the revise action except only in the document rows. If it is a revise for a part we don't do anything.

    I tried to add a screen print but the forum window doesn't show a browse to button for some reason.

    -Don

  • The property name for the column that displays "Document" or "Part" is "item_type".

    the ItemType I am working in is named "a_CN_Affected_Item" and i am putting the code in a method in the server events tab.

  • I see. In that case, I don't see anything immediately wrong with the code that you provided. My next suggestion would be to debug into the method and step through the code to make sure that your if statements are working as intended. 

  • Chris,

    In your script below, shouldn't the "//The affected item Is a document" be after the else, not before? (shouldn't hey be switched the other way around - or no?)

  • You're absolutely correct! It should be switched. 

  • Yes! That works now! Thank you so much for your help Chris! Very much appreciated!