Call same client Method from different locations (Action, CUI , Form button)

Hi, I wonder what´s the best way to call the same Client Methods from a different locations. The item that triggers the Method needs different handling based on the event used as trigger. A standard ItemType "Action" Method may work like this:
var inn = this.newInnovator()
var myItem = this; // passed with Action
return aras.AlertError("This is " + this.getProperty("name"));
For a Form button onClick this will work:
var myItem = parent.thisItem; // form call
return aras.AlertError("This is " + myItem.getProperty("name"));
CUI elements seem to need an additional call for the Item
var id;
var topWindow = aras.getMostTopWindowWithAras(window);
if (topWindow.work && topWindow.work.grid) 
{ 
    // in case Method is triggered from Main-Window-
    var workFrame = topWindow.work; 
    id = workFrame.grid.getSelectedID();
} 
else 
{
    // in case Method is triggered from Tearoff Window
    id = thisItem.getID();
}

var myItem = inn.getItemById("/*Itemtype*/", id);
return aras.AlertError("This is " + myItem.getProperty("name"));
Form and Actions can be unified in one Method this way:
var myItem;
if (parent.thisItem === undefined){
    myItem = this; // Action call
}
else 
{
    myItem = parent.thisItem; // form call
}

return aras.AlertError(myItem.getProperty("name"));
But I wonder if it´s possible to extend this construct to CUI elements? Background: I have a few Actions, that I want to move to CUI elements. But I don´t want to change anything adhoc. So I would prefer to have more flexible Methods that I can reuse more easily. Thx! Regards Angela
Parents
  • Hi Angela, You can try passing in the inArgs and/or the inDom into your GetItemFromWindow method. It looks like inArgs.control only exists if the item is called from a CUI button.
    // Call GetItemFromWindow
    var methodArgs = {
    contextWindow: window,
    contextArgs: inArgs,
    contextDom: inDom
    }
    var itm = aras.evalMethod("GetItemFromWindow", this.node, methodArgs);
    Then you can add a check to the start of your GetItemFromWindow method like...
    var win = inArgs.contextWindow;
    var contextArgs = inArgs.contextArgs;
    // The inArgs of the calling method only contain a control if it's from a CUI button
    if (contextArgs && contextArgs.control) {
    // Perform the lookup appropriate of an item from a CUI button
    }
    Chris
    Christopher Gillis Aras Labs Software Engineer
Reply
  • Hi Angela, You can try passing in the inArgs and/or the inDom into your GetItemFromWindow method. It looks like inArgs.control only exists if the item is called from a CUI button.
    // Call GetItemFromWindow
    var methodArgs = {
    contextWindow: window,
    contextArgs: inArgs,
    contextDom: inDom
    }
    var itm = aras.evalMethod("GetItemFromWindow", this.node, methodArgs);
    Then you can add a check to the start of your GetItemFromWindow method like...
    var win = inArgs.contextWindow;
    var contextArgs = inArgs.contextArgs;
    // The inArgs of the calling method only contain a control if it's from a CUI button
    if (contextArgs && contextArgs.control) {
    // Perform the lookup appropriate of an item from a CUI button
    }
    Chris
    Christopher Gillis Aras Labs Software Engineer
Children
No Data