06-07-2017 03:56 PM
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!
06-07-2017 04:04 PM
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
06-07-2017 05:03 PM
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
06-09-2017 09:25 AM
Hi Ciju.
I tried working with the JSON too and failed.
What were valid values for 'path' and 'id' in your script?
Marco
06-09-2017 09:51 AM
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.
06-09-2017 10:01 AM
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'
?
06-09-2017 10:12 AM
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
}]
}
}
06-12-2017 09:22 AM
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
Explore our Alfresco products with the links below. Use labels to filter content by product module.