Search an item by id across all item types ?.

Hello,

I sometimes had the problem that I have an ID of an Item within Aras, but I don't know the Item Type that it belongs to. (for example, I find the id in an error log somewhere but it's not clear where it came from.) Since I don't know any direct way of searching an item through all item types, I created an easy search util for that. It consists of a server-side method, a client-side method and a generic action that I can call from the main aras window. This is what the code does: - Ask the user to enter an 32-char ID. - Search through all item types for an item that has this ID - Show the result of the search: the ItemType and the keyed_name of the item that was found - It also asks the user if he/she wants to open the aras tear-off window for that item. Maybe this is helpful for other Aras users as well, so I post the code here (it's the AML that you can use to import as a small package or through AML Studio). Thomas Server side method:

<AML>
 <Item type="Method" id="6FBCE5A606B44A25AD805C1418B88388" action="add">
  <comments>Admin action to search for an ID in all ItemTypes</comments>
  <execution_allowed_to keyed_name="Administrators" type="Identity">2618D6F5A90949BAA7E920D1B04C7EE1</execution_allowed_to>
  <method_code><![CDATA[var inn = this.getInnovator();

// Validate input
var searchId = this.getProperty("search_id");
if (searchId == null)
{
    return inn.newError("Please provide a search_id");
}
if (searchId.Length != 32)
{
    return inn.newError("search_id needs to be 32 characters.");
}

// Search all available ItemTypes
var searchForItemTypes = inn.newItem("ItemType", "get");
searchForItemTypes.setAttribute("select", "name,instance_data");
searchForItemTypes.setAttribute("where", "implementation_type='table'"); // ignore polymorphic and federated ItemTypes
var allItemTypes = searchForItemTypes.apply();

// In every ItemType, search for the given ID
for (int i = 0; i < allItemTypes.getItemCount(); i++)
{
    var itemType = allItemTypes.getItemByIndex(i);
    var itemTypeName = itemType.getProperty("name");
    var tableName = itemType.getProperty("instance_data");
    // Search via SQL to avoid any permission problems
    var sql = "select keyed_name from [" + tableName + "] where id='" + searchId + "'";
    var res = inn.applySQL(sql);

    // If one item is found, return the result.
    if (res.getItemCount() > 0)
    {
        res.setAttribute("type", itemTypeName);
        return res;
    }

}

// No ID found, return error message
return inn.newError("ID " + searchId + " not found!");]]></method_code>
  <method_type>C#</method_type>
  <name>s_find_element_by_id_server</name>
 </Item>
</AML>

Client-side method:

<AML>
 <Item type="Method" id="7CF952DCB88F4EC5A2376E320AFDD05E" action="add">
  <comments>Admin action to search for a given ID in any ItemType</comments>
  <execution_allowed_to keyed_name="Administrators" type="Identity">2618D6F5A90949BAA7E920D1B04C7EE1</execution_allowed_to>
  <method_code><![CDATA[var inn = this.getInnovator();
        

// Ask the user for an ID
top.aras.prompt("Please enter ID:", "").then(
    
    // Callback function after the prompt
    function (search_id) {
    
        if (search_id===undefined) {
            // User canceled the dialog
        } else {
            
            // Check server for ID
            var r = inn.applyMethod("s_find_element_by_id_server","<search_id>" + search_id + "</search_id>");
        
            // If server returned an error, show error to user
            if (r.isError()) {
                top.aras.AlertError(r.getErrorString());
            } else {
                
                // If server found an item, show the ItemType and Keyed name of the item,
                // and ask user if he wants to see the form of the item
                if (top.aras.confirm("Search for ID: " + search_id + "\n\n" +
                    "ItemType: " + r.getType() +"\n" + 
                    "Keyed name: " + r.getProperty("keyed_name") + "\n\n"+
                    "Do you want to open the form of the item?")) {
            
                    // open form of item, if requested
                    top.aras.uiShowItem(r.getType(), search_id);
                }
            }
        }    
    }
);
]]></method_code>
  <method_type>JavaScript</method_type>
  <name>s_find_element_by_id_client</name>
 </Item>
</AML>

Action:

<AML>
 <Item type="Action" id="BAFCB980FF014963B7A6D394774F0D08" action="add">
  <item_query />
  <label xml:lang="en">Find Element By ID</label>
  <location>client</location>
  <method keyed_name="s_find_element_by_id_client" type="Method">
   <Item type="Method" action="get" select="id">
    <name>s_find_element_by_id_client</name>
   </Item>
  </method>
  <target>none</target>
  <type>generic</type>
  <name>s_find_element_by_id</name>
 </Item>
</AML>


thanks
alexsunny