Workflow notification sent to one user | Community
Skip to main content
puscasd22398856
Level 2
January 26, 2022

Workflow notification sent to one user

  • January 26, 2022
  • 2 replies
  • 3665 views

Hi guys

I have the following use case:

I created a custom workflow for publishing content into production, but only if the reviewer approves the changes that are made by the requester.

Now, the problem is that, when the workflow is created, the notification is sent to all the members of the group where is reviewer is member( I know that this is OTB functionality) and what I need to do is: only the reviewer to be notified about this workflow (because he was assigned to check the content before publishing it to production).

How do you think I can solve this one.Have you solved something like this so far?

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

lukasz-m
Community Advisor
Community Advisor
January 26, 2022

Hi @puscasd22398856, I think you could consider to use Dynamic participant step to achieve your goal. It is quite flexible i.e you could define your own dialog and write custom ecma script to handle your case. Here you can find some Adobe documentation https://experienceleague.adobe.com/docs/experience-manager-65/developing/extending-aem/extending-workflows/workflows-step-ref.html?lang=en#participant-steps-and-choosers

 

The option I can see which will be simpler, if reviewer is always the same user you can simply assign this user in participant step instead of assigning entire group.

 

Last option will be an extension of previous case. Create dedicated reviewers group and use it in participant step. Assign all users that are responsible for review to that group.

puscasd22398856
Level 2
January 26, 2022

Hi @lukasz-m thanks for your response.

I'm using Dynamic Participant Step (also I created a class that's implementing ParticipantStepChooser, where I'm overwriting the getParticipant method).The result is following: custom dynamic participant step is working fine...the workflow is assigned correctly, but the problem is that, not only the assigned user is being notified, but all group participants (all members can see the workflow from inbox : /aem/inbox and all of them can take action on that workflow, which is not correct.The only user that should be able to make action on workflow should be the reviewer).

 

@Override
public String getParticipant(WorkItem workItem,
WorkflowSession workflowSession,
MetaDataMap metaDataMap) {
final String reviewer = workItem.getWorkflow()
.getMetaDataMap().get(Constants.REVIEWER.value(), String.class);
if(reviewer != null) {
logger.debug("Workflow assigned to {}", reviewer);
return reviewer;
}else{
logger.debug("Reviewer could not be set");
return null;
}
}

 

DEBAL_DAS
January 26, 2022

1. How are you planning to select the specific reviewer in your case?

2. Are you planning to provide a dropdown with list of reviewer names to requester(content authors) after selecting your custom workflow? 

puscasd22398856
Level 2
January 26, 2022

Hi @debal_das 

1.the reviewer are fetched from the specific group ("reviewers") and displayed on the page as dropdown.

2.after choosing the desired reviewer, the workflow will start (form with submit btn)

DEBAL_DAS
January 26, 2022

From point no:1 , it means content author has ability to select desired reviewer. 

1. I have created list of users (reviewer) and assigned it to a specific group called reviewers as shown below  -

 

 

2. Created a page property called: Content Reviewer and populating same list of reviewer created in step-1

 

3. After selecting a desired reviewer , author can start the below custom workflow -

   

 

4. Here is the custom workflow process logic -

 

package com.aem.demo.core.workflows;

import java.util.Objects;

import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.granite.taskmanagement.Task;
import com.adobe.granite.taskmanagement.TaskManager;
import com.adobe.granite.taskmanagement.TaskManagerException;
import com.adobe.granite.taskmanagement.TaskManagerFactory;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.InboxItem;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.drew.lang.annotations.Nullable;
import com.google.common.base.Strings;

@8220494(property = {
Constants.SERVICE_DESCRIPTION + "=This workflow step is responsible to set Inbox Notification for Reviewer",
Constants.SERVICE_VENDOR + "=AEM Demo Debal", "process.label" + "=Content Reviewer Notification" })
public class ContentReviewerNotification implements WorkflowProcess {

private final Logger logger = LoggerFactory.getLogger(ContentReviewerNotification.class);

public static final String NOTIFICATION_TASK_TYPE = "Review Notification";

@9944223
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metadataMap)
throws WorkflowException {

ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
try {
TaskManager taskManager = resourceResolver.adaptTo(TaskManager.class);
TaskManagerFactory taskManagerFactory = taskManager.getTaskManagerFactory();
String payloadPath = workItem.getWorkflowData().getPayload().toString();
@3146596
Resource payloadResource = resourceResolver.getResource(payloadPath);

if (Objects.nonNull(payloadResource) && payloadResource.isResourceType("cq:Page")) {
Resource metadataresource = payloadResource.getChild("jcr:content");
ModifiableValueMap modifiableValueMap = metadataresource.adaptTo(ModifiableValueMap.class);

@3146596
String reviewer = modifiableValueMap.get("reviewer", String.class);

if (!Strings.isNullOrEmpty(reviewer)) {

Task newTask = taskManagerFactory.newTask(NOTIFICATION_TASK_TYPE);
newTask.setName("Content Expiry Notification");
newTask.setContentPath(payloadPath);
// Optionally set priority (High, Medium, Low)
newTask.setPriority(InboxItem.Priority.HIGH);
newTask.setDescription("Content Review Notification");
newTask.setInstructions("Content Review Notification");
newTask.setCurrentAssignee(reviewer);
taskManager.createTask(newTask);
}

}

} catch (TaskManagerException te) {
logger.error("Could not create task {} ", te.getMessage());
}

}

}

 

Here , you could see using import com.adobe.granite.taskmanagement.Task;
import com.adobe.granite.taskmanagement.TaskManager; I am able to set inbox notification for selected desired reviewer only -

 

Notification details available for admin as shown below -

 

 

But the same notification isn't available for Debal Das and Ram Sharma (admin is impersonating)

 

 

 

But it is available for debaldasone as it is assigned to him -

 

Hope this will help at some extent. Correct me if I am wrong at any point.