johni
I'm new here

Access current store element from Webedit script/workflow

Jump to solution

I want to use a script or workflow in the FirstSpirit 5 webedit which can access the current store element

The logic itself should be implemented in Java as a Executable. In the Manual (Plug-In Development / WebClient Extensions / Management Extensions / Workflow Executables / Code Example) there is an example, how to access the context and get the store element with "final StoreElement elementInWorkflow = scriptContext.getStoreElement();" but this doesn't work with scripts or workspaces which are in the actions menu. This seems to work only for the "special" deletion workflow.

So how can i access the current store element?

0 Kudos
1 Solution

Accepted Solutions
MichaelaReydt
Community Manager

Hello,

I'm not sure, if the following is the answer to your question... You want to start a workflow inside the WebClient and this workflow uses a script, which references a Executable? Inside the Executable you need the current object on which the workflow was startet?

I tested this with a very short example.

My workflow looks like this:

3.png

My script "communitytest" contains two lines:

#!executable-class

com.espirit.moddev.community.test.CommunityTestExecutable

and my Executable has the following code:

package com.espirit.moddev.community.test;

import de.espirit.firstspirit.access.script.Executable;

import de.espirit.firstspirit.access.script.ExecutionException;

import de.espirit.firstspirit.access.store.StoreElement;

import de.espirit.firstspirit.access.store.templatestore.WorkflowScriptContext;

import de.espirit.firstspirit.ui.operations.RequestOperation;

import de.espirit.firstspirit.agency.OperationAgent;

import java.io.Writer;

import java.util.Map;

/*

* Example of a simple executable class

*

* Script:

* #!executable-class

* com.espirit.moddev.community.test.CommunityTestExecutable

*/

public class CommunityTestExecutable implements Executable {

    public static final Class<?> LOGGER = CommunityTestExecutable.class;

    public Object execute(Map<String, Object> params) throws ExecutionException {

        final WorkflowScriptContext wsc = (WorkflowScriptContext) params.get("context");

       StoreElement storeElement = wsc.getStoreElement();

        //show a dialog

        OperationAgent operationAgent = wsc.requireSpecialist(OperationAgent.TYPE);

        //show the data of the current object inside a diaolog

        RequestOperation requestOperation = operationAgent.getOperation(RequestOperation.TYPE);

        requestOperation.setKind(RequestOperation.Kind.INFO);

        requestOperation.setTitle("current Object");

        requestOperation.perform("current Object: " + storeElement);

        return true;

    }

    public Object execute(Map<String, Object> context, Writer out, Writer err) throws ExecutionException {

        return execute(context);

    }

}

Starting the workflow inside the WebClient at the homepage of the Mithras-project shows me this dialog:

4.png

View solution in original post

0 Kudos
1 Reply
MichaelaReydt
Community Manager

Hello,

I'm not sure, if the following is the answer to your question... You want to start a workflow inside the WebClient and this workflow uses a script, which references a Executable? Inside the Executable you need the current object on which the workflow was startet?

I tested this with a very short example.

My workflow looks like this:

3.png

My script "communitytest" contains two lines:

#!executable-class

com.espirit.moddev.community.test.CommunityTestExecutable

and my Executable has the following code:

package com.espirit.moddev.community.test;

import de.espirit.firstspirit.access.script.Executable;

import de.espirit.firstspirit.access.script.ExecutionException;

import de.espirit.firstspirit.access.store.StoreElement;

import de.espirit.firstspirit.access.store.templatestore.WorkflowScriptContext;

import de.espirit.firstspirit.ui.operations.RequestOperation;

import de.espirit.firstspirit.agency.OperationAgent;

import java.io.Writer;

import java.util.Map;

/*

* Example of a simple executable class

*

* Script:

* #!executable-class

* com.espirit.moddev.community.test.CommunityTestExecutable

*/

public class CommunityTestExecutable implements Executable {

    public static final Class<?> LOGGER = CommunityTestExecutable.class;

    public Object execute(Map<String, Object> params) throws ExecutionException {

        final WorkflowScriptContext wsc = (WorkflowScriptContext) params.get("context");

       StoreElement storeElement = wsc.getStoreElement();

        //show a dialog

        OperationAgent operationAgent = wsc.requireSpecialist(OperationAgent.TYPE);

        //show the data of the current object inside a diaolog

        RequestOperation requestOperation = operationAgent.getOperation(RequestOperation.TYPE);

        requestOperation.setKind(RequestOperation.Kind.INFO);

        requestOperation.setTitle("current Object");

        requestOperation.perform("current Object: " + storeElement);

        return true;

    }

    public Object execute(Map<String, Object> context, Writer out, Writer err) throws ExecutionException {

        return execute(context);

    }

}

Starting the workflow inside the WebClient at the homepage of the Mithras-project shows me this dialog:

4.png

0 Kudos