Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Getting Error in calling com.adobe.icc.services.api.LetterInstanceService from AEM Workflow process step

debashisg292697
Level 2
Level 2

I am trying to get all Correspondence Letters from a workflow process step (AEM Workflow on OSGi ) , I am using the below API's but getting error related to {Code}-LCC-REP-JCR-001, {Message}-Error in getting a JCR session.

@Reference

private com.adobe.icc.services.api.LetterInstanceService letterInstanceService;

@Reference

private com.adobe.icc.services.api.LetterService letterService;

public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException  {

...

List<LetterInstanceVO> letterInstances = letterInstanceService.getAllLetterInstances(null);

// List<Letter> letters = letterService.getAllLetters(query);

...

}

Error :

com.adobe.livecycle.content.query.exception.QueryException: QueryException: {Code}-LCC-REP-JCR-001, {Message}-RepositoryException: {Code}-LCC-REP-JCR-001, {Message}-Error in getting a JCR session

at com.adobe.livecycle.content.query.impl.QueryServiceImpl.query(QueryServiceImpl.java:152)

at com.adobe.icc.services.am.GenericDaoImpl.findAll(GenericDaoImpl.java:184)

at com.adobe.icc.services.am.LetterInstanceDaoImpl.findAll(LetterInstanceDaoImpl.java:61)

at com.adobe.icc.services.core.LetterInstanceServiceImpl.getAllLetterInstances(LetterInstanceServiceImpl.java:461)

at com.aem63test.core.worflow.CorrespondenceSubmitProcess.execute(CorrespondenceSubmitProcess.java:125)

at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:193)

at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:258)

at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:500)

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:291)

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:58)

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:227)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

09.02.2018 16:35:40.166 *ERROR* [JobHandler: /etc/workflow/instances/server0/2018-02-09/abc-loan-application-process-model_7:/etc/fd/dashboard/payload/server0/2018-02-09/WL2QOKMWN2KG775CSYEOHTZFHA_7] com.adobe.granite.workflow.core.job.JobHandler Error executing workflow step

com.adobe.granite.workflow.WorkflowException: Process execution resulted in an error

Maven :

<dependency>

          <groupId>com.adobe.aemfd</groupId>

          <artifactId>aemfd-client-sdk</artifactId>

          <version>6.3.0</version>

</dependency>

I have tried with both LetterInstanceService  and LetterService  with both query parameter and null. Please suggest whether we can use this API or not. I am using AEM 6.3 + cfp + forms addon package

1 Accepted Solution
workflowuser
Correct answer by
Employee
Employee

This is the sample code snippet from my jsp page which is in production at some of our customers

Statement statement = new Statement();

statement.setAttributeName("name");

statement.setAttributeValue("Ba");

statement.setOperator(Statement.Operator.STARTS_WITH);

Query query = new Query();

List<Statement> statements = new ArrayList<Statement>();

statements.add(statement);

query.setStatements(statements);

LetterService letterService = sling.getService(LetterService.class);

List<Letter> letterList =  letterService.getAllLetters(query);

View solution in original post

15 Replies
smacdonald2008
Level 10
Level 10

Letter Service seems to be an add on. Do you have the OSGi bundle that exposes that Service in an Active State.

smacdonald2008
Level 10
Level 10

Also - i am assuming you are following some sort of online AEM Docs. Can you please point the community to that doc.

workflowuser
Employee
Employee

I will send you a sample code snippet that I have used in jsp page

never used it as part of a workflow step

what is the use case for doing it as part of aem workflow step?

workflowuser
Correct answer by
Employee
Employee

This is the sample code snippet from my jsp page which is in production at some of our customers

Statement statement = new Statement();

statement.setAttributeName("name");

statement.setAttributeValue("Ba");

statement.setOperator(Statement.Operator.STARTS_WITH);

Query query = new Query();

List<Statement> statements = new ArrayList<Statement>();

statements.add(statement);

query.setStatements(statements);

LetterService letterService = sling.getService(LetterService.class);

List<Letter> letterList =  letterService.getAllLetters(query);

View solution in original post

debashisg292697
Level 2
Level 2

workflowuser

I want to access the letter instances and generate the correspondence from the Workflow Step process. This workflow step is a part of a workflow process generated from submission of an adaptive form. Here with form data I want to generate the correspondence (Send through mail) to the customer.

Can you please suggest if this like can be done from the workflow step ?  Or correspondence letter needs to be opened from publish instance from user and then only it can be submitted ?

debashisg292697
Level 2
Level 2

Can we not render and email the correspondence letters through an AEM OSGi Worflow process step ? If yes then which API's need to be used, as com.adobe.icc.services.api.LetterService is throwing JCR session error when called from a workflow process. It works if called from a jsp.

debashisg292697
Level 2
Level 2

Hello Scott,

Can we not render and email the correspondence letters through an AEM OSGi Worflow process step ? If yes then which API's need to be used, as com.adobe.icc.services.api.LetterService is throwing JCR session error when called from a workflow process. It works if called from a jsp.

smacdonald2008
Level 10
Level 10

If its a running AEM Service - try @Reference to get a reference to the Service. Like how we use @Reference to the MailServiceGateway Service here:

Adobe Experience Manager Help | Creating custom AEM workflow steps that send email messages

debashisg292697
Level 2
Level 2

I am using @Reference to get the LetterService, but the service is throwing exception related to JCR session from the workflow process. The same exception that I mentioned in my earlier post.

It works when called from jsp.

public class TestLetterGenerationProcess  implements WorkflowProcess{

@Reference

private LetterInstanceService letterInstanceService;

@Reference

private LetterRenderService renderService;

@Reference

private LetterService letterService;

...

}

workflowuser
Employee
Employee

are you trying to render the letter and show it in the CM UI as part of workflow step?- if yes that is not possible

as To the session error, I think you need to get a service user session and associate the appropriate read permissions to the service user

i do’nt think you can use the workflow session to get access to the letter Assets

debashisg292697
Level 2
Level 2

No I want to only send the letter through email from the workflow. For this also I do need the letter instances right? Or can this be done in some other way without having to access and render the letters through any api? Is something present OOTB?

shubhankarb9134
Level 2
Level 2

Hi,

Have you got any solution for the above issue, I am also facing the same one while invoking the list of letters from the workflow process step, its giving QueryExecutionException for not having valid jcr session.

Can't we use the existing workflow session and there is no way to construct the query using valid session.

Any help would be appreciated.

Thanks
Shubhankar

sharoon23
Employee
Employee

Hi,

You are facing the issue because resource resolver is not available to the service when executed from a workflow step. When the same code is executed from jsp it works because resource resolver for the logged-in user is available by default. To provide resource resolver to the api in workflow you can use ReourceResolverHelper's callWith method and provide a service user's resource resolver which has read permissions on the path /content/apps/cm. The api LetterInstanceService/LetterService's api invocation should be done from within the callWith method. To create a service user and obtain its resource resolver you can refer the following links.

  1. AEM6: ResourceResolver access in services - WE ARE ONE INSIDE
  2. Apache Sling :: Service Authentication

This pattern of providing the resource resolver is needed whenever resource resolver is not available by default like in a workflow execution and the api being called needs access to repository.

Will get the documentation article mentioned in this thread updated to reflect this.

Thanks.

workflowuser
Employee
Employee

Adobe Experience Manager Help | Developing with Service Users in AEM Forms

Here Is link to an article on creating service user

make sure you give read permissions to content node for the” data” service user