cancel
Showing results for 
Search instead for 
Did you mean: 

Group Workflow

aishu
Champ on-the-rise
Champ on-the-rise

Dear Team,

I have created custom workflow for document review and approval for Group,

for that i have written script, but script not working properly.

please refer below script:

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "activiti$activitiReview";
workflow.parameters["bpm:workflowDescription"] = "Please assign approver for "+ document.name;
workflow.parameters["bpm:groupAssignee"] = people.getGroup("GROUP_cadgroup");

workflow.parameters["bpm:sendEMailNotifications"] = true;
workflow.execute(document);

Please suggest!

5 REPLIES 5

abbask01
Star Collaborator
Star Collaborator

have you set ${bpm_groupAssignee} in your user task group assignment. Also please provide more info - what is not working properly? are you getting any error on executing your action?

Regards,
Abbas

Nada
Champ in-the-making
Champ in-the-making

J’ai créé un flux de travail personnalisé pour examiner et approuver des documents, mais l’envoi de courrier aux utilisateurs ne fonctionne pas

yash_patel_c2
Star Contributor
Star Contributor

Do you get any errors? Is it that workflow getting started but not getting assigned to group or workflow itself is not getting started? Can you please share more details..

aishu
Champ on-the-rise
Champ on-the-rise

Hi,

issue is when I have log in with Admin 

1. I can able to make changes in file 

2. a can able to upload file

3. mail is successfully sent to users in group

but when i log in with user credentials,

above 3 points are not working.

Can u suggest?

I don't know if it is problem with some roles or permission. But I can suggest some workaround you can try if it is working or not.. From this code you will be able to run your script as admin user irrespective of the login user.

Add following java file at repo side as RunAsAdminUtil.java

package com.demo.platformsample;

import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;

/**
*
* Purpose: Creates javaScript function to run any javaScript code as administrator
*
*/
public class RunAsAdminUtil extends BaseScopableProcessorExtension {


/**
* This method runs javascript function with Admin privileges
*
* @param func
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public void runAsAdmin(final Function func) {
final Context cx = Context.getCurrentContext();
final Scriptable scope = getScope();
RunAsWork raw = new RunAsWork() {
public Object doWork() throws Exception {
func.call(cx, scope, scope, new Object[] {});
return null;
}
};
AuthenticationUtil.runAs(raw, AuthenticationUtil.getSystemUserName());
}
}

In service-context.xml register this class like this..

<bean id="runAsAdminUtil" parent="baseJavaScriptExtension"
class="com.demo.platformsample.RunAsAdminUtil">
<property name="extensionName">
<value>runAsAdminUtil</value>
</property>
</bean>

And user your code something like this..

function forRunAsAdmin(){

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "activiti$activitiReview";
workflow.parameters["bpm:workflowDescription"] = "Please assign approver for "+ document.name;
workflow.parameters["bpm:groupAssignee"] = people.getGroup("GROUP_cadgroup");

workflow.parameters["bpm:sendEMailNotifications"] = true;
workflow.execute(document);

}

runAsAdminUtil.runAsAdmin(forRunAsAdmin);

By doing this you will be able to run your script as admin user.

Hope it works for you.