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

AEM 6.4 Workflow - Assign Task - Advanced - Use custom Metadata - ECMA getUserMetaData() - how to get Workflow Metadata .. workItem Error

wendelinfa
Level 2
Level 2

We try to use Workflow Metadata inside Assign Task notification eMail.

 

Sample https://docs.adobe.com/content/help/en/experience-manager-64/forms/publish-process-aem-forms/use-met... is working fine.

 

When using var wfmetadata = workItem.getWorkflow().getMetaDataMap(); 

witch is working in participantChoser getParticipant() we get error

/apps/fd/dashboard/scripts/metadataScripts/kpbTaskMetaData_v1.ecma: ReferenceError: "workItem" is not defined. (NO_SCRIPT_NAME#28)

 

Please advice how to get Workflow Metadata based on ECMA Script in Assign Task

 

Thanks for any help

 

Regards Wendelin

1 Accepted Solution
gbedekar
Correct answer by
Level 4
Level 4

So if you are having a problem in 6.4 version, Please log a support ticket. The following code is working fine in 6.5 environment

function getUserMetaData() {
//Commented lines below provide an overview on how to set user metadata in map and return it.
var payloadPath = workItem.getWorkflowData().getPayload().toString();
log.info("The size is "+workItem.getWorkflowData().getMetaDataMap().size());
log.info("The path is "+payloadPath);

var path = workItem.getWorkflowData().getPayload().toString();
var dataFilePath = path+"/Data.xml/jcr:content";
var xPath = Packages.javax.xml.xpath.XPathFactory.newInstance().newXPath();
var factory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
var builder = factory.newDocumentBuilder();
var session = workflowSession.adaptTo(Packages.javax.jcr.Session);
var xmlDataNode = session.getNode(dataFilePath);
var xmlDataStream = xmlDataNode.getProperty("jcr:data").getBinary().getStream();
var xPath = Packages.javax.xml.xpath.XPathFactory.newInstance().newXPath();
factory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
xmlDocument = builder.parse(xmlDataStream);

node = xPath.compile("afData/afUnboundData/data/firstName").evaluate(xmlDocument, Packages.javax.xml.xpath.XPathConstants.NODE);
log.info("#####"+node.getTextContent());

 

var HashMap = Packages.java.util.HashMap;
var valuesMap = new HashMap();
valuesMap.put("policyNumber", payloadPath);
valuesMap.put("policyHolder", payloadPath);

return valuesMap;
}

View solution in original post

16 Replies
wendelinfa
Level 2
Level 2
Thanks for the Reference / is AEM Forms 6.5 equal to 6.4 (I assume Metadata handling has som major extensions)
wendelinfa
Level 2
Level 2
Thanks for the Reference / is AEM Forms 6.5 equal to 6.4 (I assume Metadata handling has som major extensions)
wendelinfa
Level 2
Level 2
Tried var test = workItem.getWorkflowData().getMetaDataMap().get(wf_mailaufgabe_subject, Packages.java.lang.String); and var test = workItem.getWorkflowData().getMetaDataMap().get("wf_mailaufgabe_subject", Packages.java.lang.String); with same error as initialy described ..
wendelinfa
Level 2
Level 2
Hello and thanks for the Links as we are on AEM Forms 6.4 variables based on the documentation are only available from AEM Forms 6.5 and newer (Starting with AEM 6.5 you can now create and use variables in AEM Workflow ..) / are ther other options?
gbedekar
Level 4
Level 4
ok,I have a custom bundle to create metadata property. I will send you that in a few hours
gbedekar
Level 4
Level 4
what is the your use case- if you could explain a little bit
wendelinfa
Level 2
Level 2
As in the sample, we notify the assignee of a task, using there a mail template and in this mailtemplate we would like to use workflow metadata or formdata (via workflow payload). As this metadata or payload access works fine in ecma script for dynamic participant as assignee we are unhappy whith the situation that this works not same way in this ecma script for custom metadata .. so we try to find the correct syntax or statements to acess wf metadata or form payload for assignee notification in Assign Task workflow component ..
gbedekar
Level 4
Level 4

I have reached out to engineering and should have an answer to you soon

gbedekar
Level 4
Level 4

this is working in the ecma script

var workflowData = workItem.getWorkflowData();

var payloadPath = workItem.getWorkflowData().getPayload().toString();

log.info("The path is "+payloadPath);

Once you get the payloadPath, you can acces the submitteddata and from there do the rest

I recommend creating osgi service to do this

Let us know if you have problems

 

wendelinfa
Level 2
Level 2

thanks for the ecma statements - this working also for us on other places like participantchoser until know but not in this custom metadata script integration.

 

Unfortunately we still get ReferenceError: "workItem" is not defined at this specific place .. is workItem generally not available in this function getUserMetaData() as described in the sample?

wendelinfa
Level 2
Level 2
I just made a test in AEM Forms 6.5 - there var workflowData = workItem.getWorkflowData() is working without problems - so in my understanding thats a error in Adobe Experience Manager: 6.4.6.0 we use actualy. Is there a chance that it is fixed on a 6.4x Version? Otherwise we will wait until we upgrading to 6.5 and 6.6
gbedekar
Correct answer by
Level 4
Level 4

So if you are having a problem in 6.4 version, Please log a support ticket. The following code is working fine in 6.5 environment

function getUserMetaData() {
//Commented lines below provide an overview on how to set user metadata in map and return it.
var payloadPath = workItem.getWorkflowData().getPayload().toString();
log.info("The size is "+workItem.getWorkflowData().getMetaDataMap().size());
log.info("The path is "+payloadPath);

var path = workItem.getWorkflowData().getPayload().toString();
var dataFilePath = path+"/Data.xml/jcr:content";
var xPath = Packages.javax.xml.xpath.XPathFactory.newInstance().newXPath();
var factory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
var builder = factory.newDocumentBuilder();
var session = workflowSession.adaptTo(Packages.javax.jcr.Session);
var xmlDataNode = session.getNode(dataFilePath);
var xmlDataStream = xmlDataNode.getProperty("jcr:data").getBinary().getStream();
var xPath = Packages.javax.xml.xpath.XPathFactory.newInstance().newXPath();
factory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
xmlDocument = builder.parse(xmlDataStream);

node = xPath.compile("afData/afUnboundData/data/firstName").evaluate(xmlDocument, Packages.javax.xml.xpath.XPathConstants.NODE);
log.info("#####"+node.getTextContent());

 

var HashMap = Packages.java.util.HashMap;
var valuesMap = new HashMap();
valuesMap.put("policyNumber", payloadPath);
valuesMap.put("policyHolder", payloadPath);

return valuesMap;
}

View solution in original post

wendelinfa
Level 2
Level 2
Great - Thanks a lot for the sample Script - works fine in 6.5 / will raise a Ticket for our 6.4 environment