myothet
2/8/2017 - 6:41 AM

Get Part BOM (javascript)

Get Part BOM (javascript)

var innovator = this.getInnovator();
// Set up the query Item.
var qryItem = this.newItem("Part","get");
qryItem.setAttribute("select","item_number,description,cost");
qryItem.setID(myId);
// Add the BOM structure.
var bomItem = this.newItem("Part BOM","get");
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
qryItem.addRelationship(bomItem);
// Perform the query.
var results = qryItem.apply();
// Test for an error.
if (results.isError()) {
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
return;
}
// Get a handle to the BOM Items.
var bomItems = results.getRelationships();
var count = bomItems.getItemCount();
// Create the results content.
var content = "<table border='1'>" +
"<tr>" +
"<td>Part Number</td>" +
"<td>Description</td>" +
"<td>Cost</td>" +
"<td>Quantity</td>" +
"</tr>";
// Iterate over the BOM Items.
for (var i=0; i<count; ++i)
{
// Get a handle to the relationship Item by index.
var bom = bomItems.getItemByIndex(i);
// Get a handle to the related Item for this relationship Item.
var bomPart = bom.getRelatedItem();
content += "<tr>" +
"<td>" + bomPart.getProperty("item_number") + "</td>" +
"<td>" + bomPart.getProperty("description") + "</td>" +
"<td>" + bomPart.getProperty("cost") + "</td>" +
"<td>" + bom.getProperty("quantity") + "</td>" +
"</tr>";
}
return content + "</table>";