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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Changing the DOR for the Using API to generate Document of Record in AEM Forms

Avatar

Level 2

Hello,

 

I have implemented the sample and it works but I am not sure how to point this to my real DOR.

Any help would be great.

Noelle

15 Replies

Avatar

Employee

Can you please give some more details of the use case?

Avatar

Level 2

Hi,

 

The sample form has a button that uses the API to produce a "preview" of the DOR with the content of the adaptive form.  When I implemented the button on my form it still uses the DOR of the sample form.

Below is the function as you can see the DOR for the sample is hardcoded.

/**
* Get pdf
* @Return {OPTIONS} drop down options
*/
function getPdf()
{
console.log("in view pdf");
window.guideBridge.getDataXML(
{
success: function(result) {
var formData = new FormData();
formData.append("dataXml",result.data);
console.log("got data"+result.data);
var settings ={
"async": true,
"url": "/content/AemFormsSamples/getdor.html",
"method": "POST",
data:{'data':result.data},
}
$.ajax(settings).done(function(response)
{
console.log("got response");
window.open(JSON.parse(response).filePath,'_blank');
})

},
error:function(guideResultObject) {console.log("got error"); },
guideState : null,
boundData : true});

}

Avatar

Employee

Do you have a specific template that you want to merge the data with?

 

Avatar

Level 2

Yes, It is attached my form.  What I don't understand is why the sample hard codes the DOR to the sample and doesn't reference the form that it is being called from.

Avatar

Employee

I am in the process of updating the sample code to take in the xdp name in the request parameters

that way you can use the code to meet your use case

Avatar

Employee Advisor

@NoelleSmith81 The dor in the sample takes the dor xdp node path from the jsp, you can update the ajax call and send a parameter in the function on the button click that has the form path. you can get this parameter in JSP just like data and that's it.

 

 

in form

const='some path'

 getPdf(const)

 

update ajax

 

function getPdf(formPath)
{

 

 

update the jsp as well.

Avatar

Level 2

Hi

 

So I have jumped back on to this after dealing with a major system crash.  When I do a console review it is telling me.
https://cfondevwvasd046.istc-inf.local/content/AemFormsSamples/getdor.html 404 (Not Found)

 

It was working before but I was on an OSGI server where the new one is J2EE.

 

@Mayank_Gandhi You mentioned updating the jsp file. Where would I find this?

 

Thanks

Noelle

 

Noelle

Avatar

Level 2

Hi

I did but it seems my install location isn't the norm and maybe causing my initial issue.  I have it setup https://xxxxxxxxxxxxxx.xxx/lc/

 

Do I need to make changes to any of the code for it to look in the right folder?

 

Noelle

Avatar

Employee Advisor

@NoelleSmith81 That should be ok, the change will be in the URL, where ever you have /content => replace it with /lc/content

 

in code and browser url as well.

Avatar

Level 2

@Mayank_Gandhi 

Here is the code, I highlighted in green where I added the /lc/.  It is still not working. --->
Post.jsp

<%--

Get Document of Record using API

 

--%><%
%><%@include file="/libs/foundation/global.jsp"%>
<%@page session="false" %>
<%@ page import="java.io.InputStream,java.io.InputStream,javax.jcr.*,org.apache.sling.commons.json.io.*,java.io.*" %>
<%@ taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>
<sling:defineObjects/>
<%
String dataXml = request.getParameter("data");
System.out.println("Got "+dataXml);
Session session;
com.adobe.aemds.guide.addon.dor.DoRService dorService = sling.getService(com.adobe.aemds.guide.addon.dor.DoRService.class);
System.out.println("Got ... DOR Service");
com.mergeandfuse.getserviceuserresolver.GetResolver aemDemoListings = sling.getService(com.mergeandfuse.getserviceuserresolver.GetResolver.class);
System.out.println("Got aem DemoListings");
resourceResolver = aemDemoListings.getFormsServiceResolver();
session = resourceResolver.adaptTo(Session.class);
resource = resourceResolver.getResource("/lc/content/forms/af/sandbox/1201-borrower-payments");
com.adobe.aemds.guide.addon.dor.DoROptions dorOptions = new com.adobe.aemds.guide.addon.dor.DoROptions();
dorOptions.setData(dataXml);
dorOptions.setFormResource(resource);
java.util.Locale locale = new java.util.Locale("en");
dorOptions.setLocale(locale);
com.adobe.aemds.guide.addon.dor.DoRResult dorResult = dorService.render(dorOptions);
byte[] fileBytes = dorResult.getContent();
com.adobe.aemfd.docmanager.Document dorDocument = new com.adobe.aemfd.docmanager.Document(fileBytes);

resource = resourceResolver.getResource("/content/usergenerated/content/aemformsenablement");
Node paydotgov = resource.adaptTo(Node.class);
java.util.Random r = new java.util.Random();
String nodeName = Long.toString(Math.abs(r.nextLong()), 36);
Node fileNode = paydotgov.addNode(nodeName+".pdf","nt:file");
System.out.println("Got paydotgov....");
System.out.println("Created file Node...."+fileNode.getPath());
Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
Binary binary = session.getValueFactory().createBinary(dorDocument.getInputStream());
contentNode.setProperty("jcr:data", binary);
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("filePath");
writer.value(fileNode.getPath());
writer.endObject();
session.save();

 

%>

 

getdor.js

 

/**
* Get pdf
* @return {OPTIONS} drop down options
*/
function getPdf()
{
console.log("in view pdf");
window.guideBridge.getDataXML(
{
success: function(result) {
var formData = new FormData();
formData.append("dataXml",result.data);
console.log("got data"+result.data);
var settings ={
"async": true,
"url": "/lc/content/AemFormsSamples/getdor.html",
"method": "POST",
data:{'data':result.data},
}


$.ajax(settings).done(function(response)
{
console.log("got response");
window.open(JSON.parse(response).filePath,'_blank');
})

},
error:function(guideResultObject) {console.log("got error"); },
guideState : null,
boundData : true});

}

Avatar

Employee Advisor

@NoelleSmith81 You did correctly. Drop me your email I will connect with you directly.