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
  • I know this thread is quite old, but I still like the topic, cause Method calls are an everyday tasks.

    I wonder if the shown calls will still work with Innovator 12. Especially as we now have even more options to use CUI elements.

    One topic is how to deal with CUI dropdowns. Another one the call of Methods from CUI elements that we use in relationships. I so far weren´t able to create a working CUI button in a relationship toolbar or popup menu. I weren´t able to figure out if a custom CUI element will be used in ALL relationships assigned to an ItemType, or if it´s possible to just show it in one specific relationship. And how can be pass the relationship item, related item or even parent item from a CUI button? So far I still use regular Actions for this task. I assume this topics get more relevant in the future.
    But if anyone knows a sample for this specific situations, I would be happy to know!

    I didn´t had the possibly to submit this one as community project yet. I somehow still wait that Aras one day will apologize for a few silly bugs in the past. Definitely had a couple of strange encounters when people with no technical background knowledge suddenly think they can improve Innovator by searching a scapegoat. Instead of searching they should better have joined some of the forum discussion or comm-projects, they definitely bring much more benefit Sunglasses.

    But I am also not sure if the potential scope of this idea still fits to Innovator 12. We probably cannot cover any event context with one Method. But at least provide enough samples to make daily life easier.

Reply
  • I know this thread is quite old, but I still like the topic, cause Method calls are an everyday tasks.

    I wonder if the shown calls will still work with Innovator 12. Especially as we now have even more options to use CUI elements.

    One topic is how to deal with CUI dropdowns. Another one the call of Methods from CUI elements that we use in relationships. I so far weren´t able to create a working CUI button in a relationship toolbar or popup menu. I weren´t able to figure out if a custom CUI element will be used in ALL relationships assigned to an ItemType, or if it´s possible to just show it in one specific relationship. And how can be pass the relationship item, related item or even parent item from a CUI button? So far I still use regular Actions for this task. I assume this topics get more relevant in the future.
    But if anyone knows a sample for this specific situations, I would be happy to know!

    I didn´t had the possibly to submit this one as community project yet. I somehow still wait that Aras one day will apologize for a few silly bugs in the past. Definitely had a couple of strange encounters when people with no technical background knowledge suddenly think they can improve Innovator by searching a scapegoat. Instead of searching they should better have joined some of the forum discussion or comm-projects, they definitely bring much more benefit Sunglasses.

    But I am also not sure if the potential scope of this idea still fits to Innovator 12. We probably cannot cover any event context with one Method. But at least provide enough samples to make daily life easier.

Children
  • Hi Angela,

    The scope of this idea definitely still fits in with 12.0. The ability to reuse code is always appreciated.

    To answer your question about CUI in relationship grids, the same concepts for adding global CUI or ItemType-specific CUI still apply. Once you get the general approach for working with CUI, the same steps can be used for basically any section of the UI that you're looking to modify. The biggest thing that's going to change is the Location. If you follow along with the ItemType-specific CUI blog post, you would need to use the ItemView.RelationshipsCommandBar location instead of the ItemView.ItemCommandBar location in order to add your menu options to the relationships grid.

    In this case, we can look at Part BOM as an example.

    1. Login as admin
    2. Navigate to TOC > Administration > ItemTypes
    3. Search for and open the Part BOM ItemType
    4. Follow the same steps as this blog by adding your configuration under the Client Style tab
      1. The biggest thing to change is using the correct ItemView.RelationshipsCommandBar location

    Chris