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 Chris, interesting concept! So you use the methodArgs for passing what you want to have returned? Somehow like this? var methodArgs = { contextWindow: window } or var methodArgs = { contextWindow: cui_mwt } or var methodArgs = { contextWindow: cui_twt } I agree, that a sample project that shows the various calls would really be helpful. Is it right that we need the additional getItemById call for the cui buttons? Or is the item somehow located in the workframe?
Reply
  • Hi Chris, interesting concept! So you use the methodArgs for passing what you want to have returned? Somehow like this? var methodArgs = { contextWindow: window } or var methodArgs = { contextWindow: cui_mwt } or var methodArgs = { contextWindow: cui_twt } I agree, that a sample project that shows the various calls would really be helpful. Is it right that we need the additional getItemById call for the cui buttons? Or is the item somehow located in the workframe?
Children
No Data