This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Modify the CAD Structure

santoshr0114 - Wednesday, January 7, 2015 3:16 PM:

Hi,

How to modify the CAD Structure.

Consider the above example say in the Structure tab i need to remove CAD-00001117 and insert another CAD Document CAD-99991111. how can i do so.



DavidSpackman - Thursday, January 8, 2015 8:04 PM:

Hi Santosh, 

Hopefully the Aras Programmers Guide can help you.

What I can say is that our query will look similar to what I have shown you in your other question.

 

Remember the the IOM is only generating an AML query to send to the server. It might be a better learning experience to learn how to write the query using AML (test using AML studio). Once you have AML query, you can then work to implement that in the IOM.

 

Some examples in the Aras Programmers Guide

Types of Actions (i.e. Add, Edit, Delete)

  • 2.4.1 Item Attributes

Examples

  • 1.3 Methods and the IOM 
  • 7.9 Add an Item configuration in one transaction (javascript, but concept is the same)

 

Couple of examples in AML

<AML>
	<Item type="CAD" action="edit" select="item_number, name" where="[CAD].item_number='CAD-00001138'">
		<Relationships>
			<Item type="CAD Structure" action="add">
				<related_id>
					<Item type="CAD" action="add">
						<item_number>abc123</item_number>
						<name>Part 1</name>
					</Item>
				</related_id>
			</Item>
		</Relationships>
	</Item>
	<Item type="CAD" action="edit" select="item_number, name" where="[CAD].item_number='CAD-00001138'">
		<Relationships>
			<Item type="CAD Structure" action="delete" where="related_id=(select id from innovator.CAD where item_number='abc123')"></Item>
		</Relationships>
	</Item>
</AML>


santoshr0114 - Tuesday, January 13, 2015 3:20 AM:

Hi David,

The above AML query is working fine. As suggested i am going through the ARAS Programmers guide as well, i found the Item.removeRelationship() but when i try to use the same steps shown in AML using IOM, the result is not positive. plz find the below code.

Aras.IOM.Innovator myinn = new Aras.IOM.Innovator(arasConn);
// Get the parent Part and its CAD Structure relationships
Aras.IOM.Item parent = myinn.newItem("CAD", "get");
parent.setProperty("item_number", parentItemnumber);
//Aras.IOM.Item relateditems= parent.createRelationship("CAD Structure", "get");
parent = parent.apply();
if (parent.isError())
        return false;                                                                         //TODO: Throw Exception
parent.fetchRelationships("CAD Structure");
// Loop through the CAD Structure relationships and delete them
Aras.IOM.Item relateditems = parent.getRelationships("CAD Structure");
for (int i = 0; i < relateditems.getItemCount(); i++)
{
         Aras.IOM.Item relateditem = relateditems.getItemByIndex(i);
         Aras.IOM.Item CADStructureItem = relateditem.getRelatedItem();
                   
         if (CADStructureItem .getProperty("item_number") == dependantitemnumber)
         {
                        parent.removeRelationship(relateditem);
                        Aras.IOM.Item tmpItem = parent.apply();
                        if (tmpItem.isError())
                               return false;                                                  //TODO: Throw Exception
           }
  }

Before calling this function, i have locked the CAD Document and set the action for Update.

There is no error in the function. When i also inspect the AML of parent, its update(i.e., the specific item under the relationships is removed/deleted), but the still i am able to see that the CAD Document is shown in CAD Structure.



DavidSpackman - Tuesday, January 13, 2015 5:01 AM:

Hi Santosh, 

The removeRelationship() command only removes the relationship from the in session result, it doesn't apply the change on the server.

To change the server you will need to create a query that will uses the action="delete" command.

 

As mentioned, best suggestion for you is to learn how to add and delete parts via AML (in AML studio). Once you can created AML that can add/delete relationships, you can then work to recreate the same query in the IOM.

 

Here is one example (very quick if you know the ID of the item you want to delete)

// Set up the query Item.
Item query = MyInnovator.newItem("CAD", "edit");
query.setAttribute("select", "item_number,name");          
query.setAttribute("where", "[CAD].item_number='CAD-00001114'");

// Add the CAD Structure
Item query1 = MyInnovator.newItem("CAD Structure", "delete");
//This is the ID of the CAD structure item (related item is CAD-00001117
query1.setID("A0088D3209214B3B8AE997F0F4D45EEC");

query.addRelationship(query1);

// Perform the query.
Item res = query.apply();

Here is another way to run the command (Maybe not the most efficient, but it shows you some features of the IOM)

// Set up the CAD Item.
Item query = MyInnovator.newItem("CAD", "get");
query.setAttribute("select", "item_number,name");          
query.setAttribute("where", "[CAD].item_number='CAD-00001114'");

// Add the CAD Structure
Item query1 = MyInnovator.newItem("CAD Structure", "get");
query1.setAttribute("select", "related_id(item_number,name)");
query.addRelationship(query1);

// Perform the query.
Item res = query.apply();

// Test for an error.
if (res.isError())
{
	return MyInnovator.newError("Item not found: " + res.getErrorDetail());
}

// Iterate over the CAD Items.
for (int i = 0; i < res.getItemCount(); i++)
{
	Item CADItem = res.getItemByIndex(i);

	// Get a handle to the BOM Items.
	Item CADStructures = CADItem.getRelationships("CAD Structure");
	int CADStructuresCount = CADStructures.getItemCount();

	// Iterate over the CAD Structure Items.
	for (int j = 0; j < CADStructuresCount; j++)
	{
		// Get a handle to the relationship Item (CAD) by index.
		Item CADStructure = CADStructures.getItemByIndex(j);
		// Get a handle to the related Item for this relationship Item.
		Item CADStructureCADItem = CADStructure.getRelatedItem();

		if (CADStructureCADItem.getProperty("item_number") == "CAD-00001117")
		{
			query.setAction("edit");
			query1.setAction("delete");
			query1.setID(CADStructure.getID());
		}
	}
}

//If the part was found
if (query.getAction() == "edit")
{
	// Perform the query.
	Item res2 = query.apply();

	// Test for an error.
	if (res2.isError())
	{
		return MyInnovator.newError("Item not found: " + res2.getErrorDetail());
	}
}

Here are some other examples of action="delete" that are good reading.

http://www.aras.comhttp://www.aras.com/Community/forums/p/7330/15171.aspx

http://www.aras.comhttp://www.aras.com/Community/forums/t/1382.aspx

http://www.aras.comhttp://www.aras.com/Community/forums/t/469.aspx



santoshr0114 - Tuesday, January 13, 2015 8:43 AM:

Hi David,

Thank you for your guidance. I ll follow your approach.