admin 发表于 2018-8-1 13:41:14

【Aras二次开发】通过Item查询关系Item信息

Technique
To query for an Item and retrieve its structure you build the query as the structure
you want returned.Use the IOM methods to add the relationships you want and
build the structure in the Item.The server will return the structure that follows the
request structure.
This recipe illustrates several related concepts together, which are how to get a set
of Items from an Item and how to iterate over the set, plus how to get the related
Item from the relationship Item.
JavaScript
var innovator = this.newInnovator();

// 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>";




C#
Innovator innovator = this.newInnovator();

// Set up the query Item.
Item qryItem = this.newItem("Part","get");
qryItem.setAttribute("select","item_number,description,cost");
qryItem.setID(myId);

// Add the BOM structure.
Item bomItem = this.newItem("Part BOM","get");
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
qryItem.addRelationship(bomItem);

// Perform the query.
Item results = qryItem.apply();

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

// Get a handle to the BOM Items.
Item bomItems = results.getRelationships();
int count = bomItems.getItemCount();
int i;

// Create the results content.
string 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 (i=0; i<count; ++i)
{
// Get a handle to the relationship Item by index.
Item bom = bomItems.getItemByIndex(i);
// Get a handle to the related Item for this relationship Item.
Item 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>";
}
content += "</table>";

return innovator.newResult(content);







    Page 46

Copyright 2007
Aras Corporation.
All Rights Reserved.
VB.Net
Dim innovator As Innovator = Me.newInnovator()

' Set up the query Item.
Dim qryItem As Item = Me.newItem("Part","get")
qryItem.setAttribute("select","item_number,description,cost")
qryItem.setID(myId)

' Add the BOM structure.
Dim bomItem As Item = Me.newItem("Part BOM","get")
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
qryItem.addRelationship(bomItem)

' Perform the query.
Dim results As Item = qryItem.apply()

' Test for an error.
If results.isError() Then
Return innovator.newError(results.getErrorDetail())
End If

' Get a handle to the BOM Items.
Dim bomItems As Item = results.getRelationships()
Dim count As Integer = bomItems.getItemCount()
Dim i As Integer

' Create the results content.
Dim content As String = "<table border='1'>" + _
"<tr>" + _
    "<td>Part Number</td>" + _
    "<td>Description</td>" + _
    "<td>Cost</td>" + _
    "<td>Quantity</td>" + _
"</tr>"

' Iterate over the BOM Items
For i = 0 To count - 1
' Get a handle to the relationship Item by index.
Dim bom As Item = bomItems.getItemByIndex(i)

' Get a handle to the related Item for this relationship Item.
Dim bomPart As Item = 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>"
Next
content += "</table>"

Return innovator.newResult(content)

页: [1]
查看完整版本: 【Aras二次开发】通过Item查询关系Item信息