How to send a form PDF via the JSON tool

Confluence User - 09 Oct, 2020

Hi,

I am a trying to use the JSON tool to send the PDF of a form to a content server. Similar idea to the Export Form Email tool but instead of sending via email, the PDF will be sent using the content server API. So far I have been able to authenticate with the content server and pass basic data using the JSON tool. However I do not know how to generate a PDF and send it via the tool.

Anybody would know how to do that?

I tried to use a process variable to store the byte stream but unfortunately I got this error. Looks like process variables take only strings ...

945
ERROR 09 Oct 2020 14:36:51 Shark - Activity[Process Id=19_json_tool_dx_kb_process1, Id=37_19_json_tool_dx_kb_process1_tool3, ba=null, ActDefId=tool3] - failed to set the activity result
946
WARN 09 Oct 2020 14:36:51 org.joget.workflow.model.service.WorkflowManagerImpl - Invalid data type for variable formpdf, required type=java.lang.String, provided type=class [B, oldval=, value=[B@603d39f4


This is the bean shell code that I am trying to use


import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.service.FormPdfUtil;
import org.joget.workflow.model.service.*;

AppDefinition appDef = AppUtil.getCurrentAppDefinition();
String formId = "form1";
String id = "0001";

//generate the pdf file in bytes
byte[] pdf = FormPdfUtil.createPdf(formId, id, appDef, null, null, null, null, null, null, null, null);

WorkflowManager wm = (WorkflowManager) pluginManager.getBean("workflowManager");
wm.activityVariable("#assignment.activityId#","formpdf", pdf);

json;forms;pdf;api

3


12 Oct, 2020
confluenceUser
confluenceUser

Hi Ian,

Thank you for your response. I am very new to Joget and having a hard time figuring out how to pass in the PDF byte stream to the Json Tool. 

I have some bean shell code that is creating the byte stream.

******

AppDefinition appDef = AppUtil.getCurrentAppDefinition();
String formId = "form1";
String id = "0001";

//generate the pdf file in bytes
byte[] pdf = FormPdfUtil.createPdf(formId, id, appDef, null, null, null, null, null, null, null, null);

String base64String = Base64.encodeBase64String(pdf);
return (base64String);

******


My problem is how do I get that value returned to the Json Tool?

From my reading looks like the only two ways to store this value is in a workflow variable or an environment variable. I tried a workflow variable but the type is not supported.

Then I tried an environment variable (and inserted the code above in there)

In Json Tool I reference the environment variable as #beanshell.mypdf#


This did not work as.

Am I doing it right?

Thanks

15 Oct, 2020
confluenceUser
1
confluenceUser

Was finally able to do this by following these instructions

https://www.baeldung.com/httpclient-post-http-request

Did not have to change to base64

Thanks

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print