Accessing 'Folder' form field

cancel
Showing results for 
Search instead for 
Did you mean: 
jvaidya
Active Member II

Accessing 'Folder' form field

How do you access the entry for the Upload Folder form field in Activiti Process Services in a Script Task? 

You can do this for a file with : 

import com.activiti.service.runtime.RelatedContentService;
import com.activiti.service.runtime.RelatedContentStreamProvider;
import com.activiti.domain.runtime.RelatedContent;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import java.nio.charset.StandardCharsets;
String fileVariableName = "file";
List<RelatedContent> contentList = relatedContentService.getFieldContentForProcessInstance(execution.getProcessInstanceId(), fileVariableName, 1, 0).getContent();
RelatedContent content = contentList.get(0);
out.println("GDH :" + content.getName());
execution.setVariable("file_name", content.getName());

How would I modify this to give me the path of the folder uploaded? 

Thanks!

7 Replies
cjose
Senior Member II

Re: Accessing 'Folder' form field

Hi Jay,

The folder information is stored as JSON String. Please check the last section of Configuring the folder entity parent | Alfresco Documentation for more details.

Ciju

cjose
Senior Member II

Re: Accessing 'Folder' form field

I just tested it and found that it is actually stored as a HashMap instead of a JSON String. Did you notice that too?

I can print the selected Folder ID using the following groovy script in a script bpmn component.

if(execution.getVariable('variablename'))
println execution.getVariable('variablename')['path']['id']

Can you please raise a defect with the documentation where it says the data is stored as JSON String which is not quite correct?

Ciju

mrahn
Active Member II

Re: Accessing 'Folder' form field

Hi Ciju.

I tried working with the JSON too and failed.

What were valid values for 'path' and 'id' in your script?

Marco

cjose
Senior Member II

Re: Accessing 'Folder' form field

That's part of the folder value which is stored as a Map<String, Map>. Please refer Configuring the folder entity parent | Alfresco Documentation  for more details.

mrahn
Active Member II

Re: Accessing 'Folder' form field

Yes, I know this part of the documentation.

It says it's a JSON, e.g.

{"path":{"id":"47cb278d-c775-444f-a23e-b9f2d92390da","title":"documentLibrary > my-folder","folderTree":[{"id":"ec5eb0ec-76a0-4175-adbf-dcf3842ed00c","title":"documentLibrary","simpleType":"folder","folder":true},{"id":"47cb278d-c775-444f-a23e-b9f2d92390da","title":"my-folder","simpleType":"folder","folder":true}]},"

Taking this example, what are the values for path and id in your script?

path: 'documentLibrary > my-folder'

id: '47cb278d-c775-444f-a23e-b9f2d92390da'

?

cjose
Senior Member II

Re: Accessing 'Folder' form field

Map['path']['id'] is a groovy way of navigating into the java.util.LinkedHashMap and fetching the id from the Map which is a value of Key named path... I beautified the JSON as shown below

{
"path": {
"id": "47cb278d-c775-444f-a23e-b9f2d92390da",
"title": "documentLibrary > my-folder",
"folderTree": [{
"id": "ec5eb0ec-76a0-4175-adbf-dcf3842ed00c",
"title": "documentLibrary",
"simpleType": "folder",
"folder": true
}, {
"id": "47cb278d-c775-444f-a23e-b9f2d92390da",
"title": "my-folder",
"simpleType": "folder",
"folder": true
}]
}
}
mrahn
Active Member II

Re: Accessing 'Folder' form field

ok, understood.

I was looking for a way to define the parent programatically when creating a folder using the Store Entity Task.

We found that one could use a hash map like the one above or just the uuid of the parent folder. So we went for the uuid and it works fine.

Thank you for your support.

Marco