Forum Discussion

hkhan's avatar
hkhan
Ideator I
5 years ago

How to Run already existing Action from a relationship

I have this action which runs fine on an itemtype1, I want to use the same action to be triggered when i am on another itemtype2 but itemtype1 is in a relationship. 

Currently im getting an error when i click that action from the relationship,

3 Replies

  • Probably an issue with the id of your target Item. When you want to use an Action in a grid AND relationship grid, you have to differentiate this in your Method. There are a couple of ways to do this. This is one of them:

    var myId = null;
    var myItem = null;
    // Determine if Action was called from main grid or relationship grid
    var relatedId = this.getProperty("related_id","");

    // relatedId only exists when Action is called from relationship grid
    if (relatedId)
    {
    myId = relatedId;
    myItem = this.getPropertyItem("related_id");
    }
    else
    {
    myId = this.getID();
    lytem = this;
    }

    • hkhan's avatar
      hkhan
      Ideator I

      Hello Angelalp

      Im still getting error i added my code in your code below is that 

      The action basically help triggers a workflow on an action, It works fine when i do it on an item type but it has issues when i do it on a relationship grid

      Innovator inn = this.getInnovator();
      Aras.IOM.Innovator innovator = this.getInnovator();
      // var myId;
      // var myItem;
      // Determine if Action was called from main grid or relationship grid
      var relatedId = this.getProperty("related_id","");

      // relatedId only exists when Action is called from relationship grid
      if (relatedId)
      {
      var myId = relatedId;
      var myItem = this.getPropertyItem("related_id");
      }
      else
      {
      var myId = this.getID();
      var lytem = this;
      }


      string workflowMapName = "VSY Task";
      Item workflowMap = innovator.getItemByKeyedName("Workflow Map", workflowMapName);
      if ((workflowMap == null) | (workflowMap.getID().Length != 32))
      {
      return innovator.newError("Unable to retrieve Workflow Map '" + workflowMapName + "'");
      }
      // Instantiate and start the workflow.
      Item workflow = this.instantiateWorkflow(workflowMap.getID());
      if (workflow.isError())
      {
      return innovator.newError("Error instantiating workflow: " + workflow.getErrorDetail());
      }
      workflow.startWorkflow();
      return this;

      • AngelaIp's avatar
        AngelaIp
        Ideator I

        Ah ok. Your question was about something different than I expected.

        For this usecase you can´t just copy paste my code, it was buggy anyway ;-)

        What do you want to achieve? What is your current code doing? You seem to call your Workflow map, but for which purpose?