call client method from sevrer

How can i call client method from server?    
  • Hello, It is not possible to call a client method from within a server method. Could you elaborate on your use case for this? It's likely possible to achieve the desired result through different means. Chris
    Christopher Gillis Aras Labs Software Engineer
  • Thanks for help.. In this scenario i want to give a call to client method  where i am using "alertWarning " through server events? how i can achieve this? By any other different ways?
  • Hi Mily, Where is your server method being called from? If the method is being called from a Server Event on an ItemType, you can use a line like return inn.newError("My warning message"); to display a dialog with to the user. Chris
    Christopher Gillis Aras Labs Software Engineer
  • Hi, I have also one use case where it would be helpful to call a client Method from a server Method. But maybe there is also another way to solve it. The Action PE_CreateNewRevision can be used to create a new manual revision of a Part. In most cases, the Form and Relationships update automatically after clicking the Action. But sometimes that does not work, e.g. when repating this Action. I also have seen that sometimtes the Form will update, but the Relationships still link to the old source_id. It´s not a big issue right now, but sometimes users are forced to reopen the Parts and repeat the changes. So it would be practical if the Form and Relationship always (!) refreshes automatically after clicking "PE_CreateNewRevision". Also "PE_CreateNewRevision" is a CSharp server method, so I don´t know how to add the Javascript refresh there. One option is maybe, to rewrite the Action to a client version that calls another CSharp Method for updating the database values. I also do not want to exclude that I have some mistake in my code that prevents the refresh. But maybe somebody knows an easy and elegant way to improve this? Angela
  • As soon as I type something in the forum, I normally have an idea for solution 1 hour later... My usecase can be solved by an extra Method in the Action On Complete field. I added this code and was able to improve the "refresh" behaviour:
    var inn = this.getInnovator();
    var parentItm = this.getType();
    var parentID = this.getID(); 
    
    // Get the config_id
    var item = inn.newItem(parentItm, "get");
    item.setID(parentID);
    item.setAttribute("select","config_id");
    item = item.apply();
    var configID = item.getProperty("config_id");
     
    // get the most recent part with config_id
    var currentItm = inn.newItem(parentItm, "get");
    currentItm.setProperty("config_id", configID);
    currentItm.setProperty("is_current", "1");
    currentItm = currentItm.apply();
    
    // show new item in frame of previous item
    aras.uiReShowItem(parentID,currentItm.getID(),'view','tab view');
  • Angela, That is a nice solution.  Thanks for sharing it.  Do you think the On Complete method approach could also be used to simply refresh the item form?  I have a problem where my server method saves and unlocks the item, but the form still shows the item as locked.  I am hoping this would be a good way to clean that up. Thanks, John
  • Hi John, it depends. There are multible ways to update something in Aras. These are the ones I have used so far: 1. parent.onRefresh - I often use this one in the callback Method of Javascript Form handlers. 2. aras.uiShowItem("Part", id); - just show an item 3. aras.uiReShowItem(parentID,newID,'view','tab view'); - reshow item 4. aras.uiReShowItemEx(parentID,doc.newItem.node); - similar to uiReShowItem 5. aras.clearClientMetadataCache(); I have seen this often in other samples here in the Forum, but I prefer the other options. For updating the grid there are other options avaiable (runSearch, updateRow). You can find them often in the code of CUI elements. Maybe this one is also option for you. This is a very reduced breakout from an Action I use in the BOM Relationship. It updates the Form after the job were done.
    var bomID = this.getID(); // get id of BOM relationship
    var body =  "<bom_>" + bomID + "</bom_>";
    var result = aras.applyMethod("My server Method",body); // do some server side stuff
    
    parent.onRefresh(); // Refresh Part
    return null;
    From my current POV, the above sample is not as reliable as I expected it to be and still requires some further testing. So maybe this one is a better option. Angela