Get relationship items from idlist

Hi Community,

Super random question here. I am working on a method to automatically update properties based on a property on the CAD item type. I am setting up the method to -

1. Get the property from the CAD Document (Drawing)

2. Create an idlist of the related parts and apply the property to those items

3. Get the related Document items of said parts and apply the property to those items

4. Get the related CAD Document for the Model from the relationship with the part and apply the property.

I have completed 1 and 2 just fine but I am having a brain freeze on how to get the relationships from the Part. Can I do this with the idlist of Parts I've already setup or should I build a new item collection from the source_ids I get with the initial item query to create the idlist.

Just looking for best practice on this.

Thanks in advance!

  • Is the Document in your step 3 the 'Document' ItemType or also a 'CAD Document'?

    If yes, is this one correct? You update one property of a CAD Document, and want to update all other CAD Document that are associated by Parts? Maybe you can provide a drawing?

  • Hello Angela,

    Yes, as an example:

    I have a CAD Document with ECO field - our drafting team fills in a solidworks property in the CAD which is carried to Aras via the connector, in this example 300219

    I then have an OnAfterUpdate method that takes the number and proliferates it to all the Parts that are related to this drawing via Part CAD relationship:

    This part is working fine.

    The next step I need is for all of these parts, let's take UAAB50500, if there is a Document related to it via Part Document, I need that document ECO to update as well:

    Lastly, the model for this part needs to be updated to include the ECO number.

    Currently, the method looks like this, and works for the portion that updates the parts but that is where I am stuck. I want to get relationships from the parts for these so I can get a handle on their related items, but not sure if this is possible when making a query using an idlist.

            //get the Part Relationships
            Item qryPartRels = inn.newItem("Part CAD", "get");
            qryPartRels.setPropertyItem("related_id", this);
            Item partRels = qryPartRels.apply();
    
            // Create a list of Part IDs and apply the method to Part each item
            List<String> idLists = new List<String>();
    
            for (int i = 0; i< partRels.getItemCount(); i++)
                {
                idLists.Add(partRels.getItemByIndex(i).getProperty("source_id"));
                }
                
                //If any items are in the list, set the a_last_eco property to this items a_last_eco property
                if(idLists.Any())
                    {
                    Item partItem = inn.newItem("Part", "edit");
                    partItem.setAttribute("idlist", String.Join(",", idLists));
                    partItem.setProperty("a_last_eco", this.getProperty("a_last_eco"));
                    partItem = partItem.apply();
                    }

  • Got it working. Just got a handle on the parts with a new query. Not sure if the most efficient way but it works for my purposes for now.

  • Happy you got it working! Due to the complicity I assume it´s not possible to solve it with just "one" query. At least two are required, which is not a big deal and not unusual.

    Regarding efficiency I would recommend you to use  the "select" or "doGetItem" attribute. Right now you always work with full items that include all properties. This can become a performance killer when a lot of items are involved.

    You can use "select" for get-queries, and "doGetItem" for the edit, e.g. shown here:

    https://community.aras.com/b/english/posts/server-side-best-practices-part-2

  • Thanks for this Angela.

    I usually try and go back in after I ensure everything is working and add the select attribute.

    Also, after some work I did manage to get this down to a singly query for the parts which streamlined things quite a bit.

    Unfortunately my coding knowledge is mediocre at best so I take the small wins where I can :)