Forum Discussion

FICO's avatar
FICO
Community Manager
3 years ago

Hi, How can I run multiple "vdl-action-execute" in one "vdl-action-group", like sequential? When i put multiple vdl-action-execute in a vdl-action-group, only the first one runs. Thank you in advanc

9 Replies

  • FICO's avatar
    FICO
    Community Manager

    Hi Narges,

    I made a little demo that lets you load or run all the scenarios on the shelf:

    <vdl version="5.0">

      <vdl-page>

        <vdl-header>

          <vdl-action-group name="RUN_ALL">

            <vdl-action-execute vdl-repeat="=s,i in scenarios" scenario="=i"></vdl-action-execute>

          </vdl-action-group>

          <vdl-action-group name="LOAD_ALL">

            <vdl-action-confirm title="Loading input data" text="Loading data will override all existing input data. Do you want to proceed?" ok-label="Load Data" cancel-label="Cancel"></vdl-action-confirm>

            <vdl-action-execute mode="LOAD" vdl-repeat="=s,i in scenarios" scenario="=i" suppress-prompt="true"></vdl-action-execute>

          </vdl-action-group>

        </vdl-header>

        <vdl-section heading="Run All">

          <vdl-row>

            <vdl-column size="12">

              <vdl-button label="Load All" vdl-event="click:actions.LOAD_ALL"></vdl-button>

              <vdl-button label="Run All" vdl-event="click:actions.RUN_ALL"></vdl-button>

            </vdl-column>

          </vdl-row>

        </vdl-section>

      </vdl-page>

    </vdl>

    The LOAD_ALL Action group has a separate Confirm Action, you would suppress the confirmation on the Load Action so that you don't get a confirmation for each scenario.

    Joc

  • FICO's avatar
    FICO
    Community Manager

    Hi Joc,

    Thank you very much for your reply.

    Instead of scenarios, I want to run some custom functions (in only one scenario) on the backend so I want the "mode" to loop over. Something like this:

     <vdl-action-group name="RUN_ALL">

            <vdl-action-execute vdl-repeat="=i in scenario.entities.My_SET" mode="=i.value"></vdl-action-execute>

    </vdl-action-group>

    MY_SET keeps the name of my functions.

    I tried this and it doesn't work. any idea?

    I appreciate your help.

    Narges

  • FICO's avatar
    FICO
    Community Manager

    Hi Narges,

    that isn't going to work I'm afraid.

    The Execute VDL Action only queues a scenario for execution, at which point it is effectively locked. So, the second Execute Action fails because it is trying to execute the same scenario. However, if there are only a few permutations, you could create other execution modes to call one after another in the order you require, within the model.

    Would it be possible to share a use case for wanting this functionality from VDL Actions?

    Joc

  • FICO's avatar
    FICO
    Community Manager

    Hi Joc,

    I appreciate your prompt reply. Sure, this is the use case in my app:

    Let’s say I have two buttons that each executes a custom function on backend.  

    @xi.ExecMode(name="run_fun_1")

       def Fun_1 (self):

    …

    @xi.ExecMode(name="run_fun_2")

       def Fun_2 (self):

    …

    Now I want to have a third button that execute these two functions, one after another. That's what I am doing.

    Thank you

    Narges

  • FICO's avatar
    FICO
    Community Manager

    Hi Narges,

    if the use case is that simple then the approach with a third execution mode would definitely work.

    @xi.ExecMode(name="run_fun_1_2")
        def Fun_1_2(self):
            self.Fun_1()
            self.Fun_2()

    However, if there are a large number of Execution Modes and the order could be fairly dynamic then you might need to look into other methods. If there is a need for a more complex solution, let me know and I can try to help you find a better solution.

    Joc

  • FICO's avatar
    FICO
    Community Manager

    Hi Joc,

    This is actually the very first thing I tried but I get like this error:

    Cannot call the "run_fun_1" execution mode, because the "run_fun_1_2" execution mode is already running.

    Narges

  • FICO's avatar
    FICO
    Community Manager

    Hi Narges,

    As this is Python, rather than VDL, I have asked a colleague to help you with your problem.

    They should respond soon.

    Best regards,

    Joc

  • FICO's avatar
    FICO
    Community Manager

    Hi Narges,

    To avoid one execution mode calling another execution mode, you need to separate the logic into separate functions, like this:

    @xi.ExecMode(name="run_fun_1")
    def Fun_1(self):
        self.do_1()
     
    @xi.ExecMode(name="run_fun_1")
    def Fun_1(self):
        self.do_2()
     
    @xi.ExecMode(name="run_fun_1_2")
    def Fun_1_2(self):
        self.do_1()
        self.do_2()

    Where the code that you currently have in Fun_1 is moved into a new function do_1, and the code for Fun_2 is moved into do_2.

  • FICO's avatar
    FICO
    Community Manager

    Hi Chris and Joy,

    Separating the logic worked for me and I am all set! I really appreciate you guys.

    Regards,

    Narges