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
  • It´s somehow not so easy to differentiate the CUI elements from the rest. "window" is always present, I don´t know how to use this one for differentiation. The itm sometimes already contains the selected items, sometimes just an Object Element. I tried the following ones: itm.constructor.name == "Element" -> in case when Method is called from a Form (CUI twt + Action) itm.getItemCount(); -> Is -1 for CUI mwt calls and >0 for Action calls. But throws an error for CUI twt elements. Are there additional parameters passed that could be helpful?
Reply
  • It´s somehow not so easy to differentiate the CUI elements from the rest. "window" is always present, I don´t know how to use this one for differentiation. The itm sometimes already contains the selected items, sometimes just an Object Element. I tried the following ones: itm.constructor.name == "Element" -> in case when Method is called from a Form (CUI twt + Action) itm.getItemCount(); -> Is -1 for CUI mwt calls and >0 for Action calls. But throws an error for CUI twt elements. Are there additional parameters passed that could be helpful?
Children
No Data