How to pass items in applyMethod?

Hi, I have a couple of huge server Methods, that share around 90% of the same code. So I want to unify them into one large Method, and use more compact calling Methods. My current problem is to past the context Item(s) to the main Method. When I call a server Method from a server Method, the selected Items are replaced with the Method item. This is what I have tried so far:
// Method triggered from Lifecycle
string body ="<keyword_>INSERT</keyword_><items_>" + this + "</items_>"; // ???
Item res = inn.applyMethod ("MyMainMethod", body);
return res;
// Main Method
Innovator inn = this.getInnovator();
XmlDocument xDoc = new XmlDocument();
if ((this.getAttribute("type", "") == "Method") & (this.node.SelectSingleNode("items_") != null))
{
  this.node = xDoc.CreateElement(this.node.SelectSingleNode("items_").ToString());
}
string thisItemTypeName = this.getItemByIndex(0).getAttribute("type",""); // will return Method instead of original items
Is it possible to overwrite the context of "this" with the item passed in applyMethod? Thanks for any input! Best regards, Angela
Parents
  • Hi Andreas, thanks for your help! Your code basically works, but I still have some trouble to hand over the complete Item that calls the Method:
    // Calling Method
    Innovator inn = this.getInnovator();
    Item myItem = this.newItem(this.getAttribute("type"), "MyMainMethod");
    myItem.setID(this.getID());
    myItem.setProperty("keyword_","INSERT");
    Item results = myItem.apply();
    if (results.isError())
    {
        return inn.newError("Error while Insert Data. " + results);
    }
    return results;
    
    // Main Method
    Innovator inn = this.getInnovator();
    string thisItemTypeName = this.getItemByIndex(0).getAttribute("type",""); // work! will return type of calling Item instead of Method
    // Parameters passed with Method call
    string keyword = this.getProperty("keyword_","invalid"); // works
    if (keyword == "..."){}
    
    // Get properties from calling Item
    int count = this.getItemCount(); // don´t work
    string pn = this.getItemByIndex(0).getProperty("item_number", "empty"); // don´t work, will always be empty, as "this" doesn´t contain the complete original Item.
    It would be possible to extend the calling Method to handover more properties. But this would make the calling Method more complex. One alternative is to extend the Method call so it contains the original Item: myItem.setProperty("myitem_", this); But I am not sure if passing "this" is really the best solution. This will move around a lot of data, as the Method shall apply to multiple items.
Reply
  • Hi Andreas, thanks for your help! Your code basically works, but I still have some trouble to hand over the complete Item that calls the Method:
    // Calling Method
    Innovator inn = this.getInnovator();
    Item myItem = this.newItem(this.getAttribute("type"), "MyMainMethod");
    myItem.setID(this.getID());
    myItem.setProperty("keyword_","INSERT");
    Item results = myItem.apply();
    if (results.isError())
    {
        return inn.newError("Error while Insert Data. " + results);
    }
    return results;
    
    // Main Method
    Innovator inn = this.getInnovator();
    string thisItemTypeName = this.getItemByIndex(0).getAttribute("type",""); // work! will return type of calling Item instead of Method
    // Parameters passed with Method call
    string keyword = this.getProperty("keyword_","invalid"); // works
    if (keyword == "..."){}
    
    // Get properties from calling Item
    int count = this.getItemCount(); // don´t work
    string pn = this.getItemByIndex(0).getProperty("item_number", "empty"); // don´t work, will always be empty, as "this" doesn´t contain the complete original Item.
    It would be possible to extend the calling Method to handover more properties. But this would make the calling Method more complex. One alternative is to extend the Method call so it contains the original Item: myItem.setProperty("myitem_", this); But I am not sure if passing "this" is really the best solution. This will move around a lot of data, as the Method shall apply to multiple items.
Children
No Data