Hi Oliver, I solved it using oData my co-worker advised me like you mentioned.
>In you scenario, how does the user select the parent industry, and what happens after?
My Web Template has a fetchxml and javascript, when it loads it trigger fetchxml to get parent industry then it show parent dropdown list as follows.
<div class="col-sm-10">
<select id="parentindustryselect" class="form-control picklist" name="parentindustryname" onchange="showChildIndustry(value);">
{% if parentIndustryResults.size > 0 %}
{% for parentIndustry in parentIndustryResults %}
<option value="%{{parentIndustry.sab_industryid}}%">{{ parentIndustry.sab_name }}</option>
{% endfor %}
{% endif %}
</select>
</div>
When user select one of the parent industry, child industry select dropdown list needs to be populated.
What I did when form is ready get all child industry using oData then based on user selection, filtered it by parent industry and binding the result to child industry select dropdown element.
var allChildInustry = null;
$(document).ready(function () {
...
$.ajax({
type: "get",
url: "/_odata/industries_child_odata",
success: function (data) {
allChildInustry = data.value;
},
error: function () {
alert('Failed to retrieve all child industry');
}
});
});
...
function showChildIndustry(value) {
var name = $("#parentindustryselect option:selected").text();
// I can't use jQuery's grep and even filter function don't know why.
// var filterValue = $.grep(allChildInustry, function (child) {
// return child.sab_parentindustry.Id === value && child.sab_parentindustry.Name === name;
// });
// var filterValue = allChildInustry.filter(function (child) {
// return child.sab_parentindustry.Id === value && child.sab_parentindustry.Name === name;
// });
var filterValue = [];
for (var i = 0; i < allChildInustry.length; i++) {
var child = allChildInustry[i];
if (child.sab_parentindustry.Name === name) {
filterValue.push(child);
}
}
$('#childindustryselect').empty();
for (var i = 0; i < filterValue.length; i++) {
console.log(filterValue[i].sab_name + " ::::: " + filterValue[i].sab_industryid);
$('#childindustryselect').append('<option value=' + filterValue[i].sab_industryid + '>' + filterValue[i].sab_name + '</option>');
}
}
However, after selecting child industry and other criteria, it needs to show final result. It could be another fetchxml call or etc.
Anyway thanks a lot Oliver.