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!
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
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
Hi Ciju.
I tried working with the JSON too and failed.
What were valid values for 'path' and 'id' in your script?
Marco
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.
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'
?
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
}]
}
}
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
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.