I am using Alfresco Community Edition-5.1.x , we created advanced workflow. In workflow we are trying to populate web-service results values in drop-down. Can you please guide us how to populate values in drop-down?
Asked
Active
Viewed 354 times
2 Answers
1
On this sample code, I'm loading the group members into dropdown control by calling Alfresco Repo webscript.
Register the control here(in ftl file)
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<select name="${field.name}" id="${fieldHtmlId}" value="${field.value?html}" style="width: 250px;"></select>
Callback method once the data is received from the REST service
<script type="text/javascript">
function ${grpName}_loadDropDown(o){
var selectElem = YAHOO.util.Dom.get("${fieldHtmlId}");
selectElem.options.length=0;
for (; i<o.json.data.length; i++){
var user = o.json.data[i];
selectElem.options[j] = new Option(user.displayName, user.shortName, false, false);
j++;
}
}
Call the REST service here
function ${grpName}_loadData(){
var url = Alfresco.constants.PROXY_URI+"api/groups/${grpName}/children?sortBy=displayName&maxItems=100&skipCount=0";
<#if field.control.params.sortAsc?exists>
<#assign sort=field.control.params.sortAsc?html>
url+="&sortAsc=${sort}";
</#if>
Alfresco.util.Ajax.request({
url: url,
method: "GET",
requestContentType: "application/json",
successCallback:{
fn: function(o){
${grpName}_loadDropDown(o);
},
scope: this
},
failureCallback:{
fn: function(o){alert("Unable to find group or error ");},
scope: this
}
});
}
Start the REST service request here
${grpName}_loadData();
</script>

Muralidharan Deenathayalan
- 1,486
- 1
- 8
- 17
-
If REST API webservice , How we can you to populating drop-down list – JohnPaul Sep 27 '16 at 06:13
-
This is also Alfresco's inbuilt REST API only (Alfresco.constants.PROXY_URI+"api/groups/${grpName}/children?sortBy=displayName&maxItems=100&skipCount=0"; ) – Muralidharan Deenathayalan Sep 27 '16 at 07:00
-
But my web services external not alfresco inbuilt web services , how can i use external web services in alfresco and webservices result populating into drop-down list ,please help with refernces – JohnPaul Sep 27 '16 at 11:45
1
Here is the sample for you and I've the following open JSON - RSET web services to get the data.
WebService URL : https://jsonplaceholder.typicode.com/posts
The result should be something similar to the below one,
Please let me know, if you need further help on this.
<script type="text/javascript">
function ${groupName}_populateSelectData(o){
var selectElem = YAHOO.util.Dom.get("${fieldHtmlId}");
selectElem.options.length=0;
var i = 0;
var j = i+1;
for (; i<o.json.length; i++){
selectElem.options[j] = new Option(o.json[i].title, o.json[i].title, false, false);
j++;
}
}
function ${groupName}_updateList(){
var url = "https://jsonplaceholder.typicode.com/posts";
Alfresco.util.Ajax.request({
url: url,
method: "GET",
requestContentType: "application/json",
successCallback:{
fn: function(o){
${groupName}_populateSelectData(o);
},
scope: this
},
failureCallback:{
fn: function(o){alert("Error ");},
scope: this
}
});
}
${groupName}_updateList();
</script>

Muralidharan Deenathayalan
- 1,486
- 1
- 8
- 17
-
Thanks a lot i am able to use web-service and implemented in alfresco – JohnPaul Sep 28 '16 at 10:13