Get JSON values inside template

Hello

I am trying to build Connect Web Template application using Connect HTTP Input processess inside workflow and also Jquery/Ajax calls on the frontend.

Inside workflow I have 2 processess:

  1. REVIEW
  2. REVIEWDATA

I have following JSON produced by REVIEWDATA process and stored inside %9 variable

[{“ID”:“8”,“SomeNumber”:“1234”}]

Inside my template I would like to get value of this JSON fields.

Using standard script, trying to do it in this way:

var jobObj = {};

if(automation.jobInfos.JobInfo9){
jobObj = JSON.parse(automation.jobInfos.JobInfo9);
}

// Update static information in the web page
query(“#myReviewID”).text(jobObj.ID);

Unfortunatelly it seems to be undefined.

Could You please tell me how to extract this back into template?

If you’re using jQuery to make an ajax call to your REVIEWDATA process, then that process should simply return a JSON file. So at the end of your process, add a Create File task that only contains %9.

Also, make sure that the original input task for that process is set to return mime type application/json.

Finally, if your process is using the HTTP Server Input task, you should consider using the NodeJS Server Input task instead since it is more efficient and more robust.

Thank You

I am already trying to make it work, template dont see my %9 json with some reason.

The %9 is set and I am able to save json value into text file.

When I open application, the %9 seems to be undefined

Your template does not need to access %9.

Your Ajax query will retrieve the entire JSON file created by your Workflow process. So it’s that JSON response you use in your template.

The code in your template would look something like this:

$.ajax(myWorkflowURL,{async:false}).success( data =>
			{
				jobObj = data;
				query("#myReviewID").text(jobObj.ID);
			}
		);

What is myWorkflowURL? Is that HTTP Input request action? like /home or /review ?

Something like “http://localhost:8080/myActionName”.

Ok got it

Thanks

I was telling about %9 because we are holding JSON inside %9 and later parse that inside template standard script

For example to map some data, but Your solution is also very nice to know.