How to create content block with dropdowns which are corerlated

akshayp
Tera Expert

Hi,

I have to create one content block for dashboard which has two dropdowns.

One will be campaign, which are basically tasks. so thing is that, for each tasks there are some assessments which are assigned to different persons from different departments.

  so my second dropdown will be department

And also after selecting campaign i only want to see the those departments with there users assigned assessments.

Now i have one content block which is used for campaign and mega region (user's dot walking field to location)

I will add that dynamic script here please let me know what changes i need to make in it, so that i'll get departments insted of mega region for selected campaign

 

 

 

Dynamic content script-

 

<?xml version="1.0" encoding="UTF-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:g2="null" xmlns:j2="null" trim="false">
<style>table {
width: 100%;
}
table tr td {
vertical-align: top;
padding-left: 20px;
}
table label {
font-weight: bold;
font-size: medium;

}
.table-col-1 {
width: 16%;
}
.select-box {
width:80%;
}
</style>

<g:evaluate var="jvar_res" jelly="true" object="false">
jvar_res = 45345;
</g:evaluate>
<script>
var my_dashboardMessageHandler = new DashboardMessageHandler("Location_category");
var finalFilter = [];

<!-- Function to build filter conditions based on selected values -->
function publishMultipleFilters(value) {
var finalFilter = '';
var authFilter = '';
var citationFilter = '';
var valArr = value.split(',');
<!-- Final Filter condition if Location is not - empty -->
if (valArr[0] != '') {
authFilter = "u_mega_region=" + valArr[0];
citationFilter = "document.ref_sn_compliance_authority_document.u_mega_region=" + valArr[0];
}
if (valArr[1] != '') {
if (citationFilter == '')
citationFilter = "u_level_1_category=" + valArr[1];
else
citationFilter = citationFilter + "^u_level_1_category=" + valArr[1];
}
if (valArr[2] != '') {
if (citationFilter == '')
citationFilter = "u_category=" + valArr[2];
else
citationFilter = citationFilter + "^u_category=" + valArr[2];
}
if (valArr[3] != '') {
if (citationFilter == '')
citationFilter = "u_sub_category=" + valArr[3];
else
citationFilter = citationFilter + "^u_sub_category=" + valArr[3];
}
if (valArr[4] != '') {
authFilter = "u_country=" + valArr[4];

if (citationFilter == '')
citationFilter = "document.ref_sn_compliance_authority_document.u_country=" + valArr[4];
else
citationFilter = citationFilter + "^document.ref_sn_compliance_authority_document.u_country=" + valArr[4];
}
if (valArr[5] != '') {
authFilter = "u_jurisdiction_level.state=" + valArr[5];

if (citationFilter == '')
citationFilter = "document.ref_sn_compliance_authority_document.u_jurisdiction_level.state=" + valArr[5];
else
citationFilter = citationFilter + "^document.ref_sn_compliance_authority_document.u_jurisdiction_level.state=" + valArr[5];
}
if(authFilter != ''){
finalFilter = [{
"table": "sn_compliance_authority_document",
"filter": authFilter
}, {
"table": "sn_compliance_citation",
"filter": citationFilter
}];
}
else{
finalFilter = [{
"table": "sn_compliance_citation",
"filter": citationFilter
}];
}

<!--call setDefaultValue first -->
SNC.canvas.interactiveFilters.setDefaultValue({
id: my_dashboardMessageHandler.Location_category,
filters: finalFilter,
}, false);

<!--then call Publishmessage to publish filters -->
my_dashboardMessageHandler.publishMessage(finalFilter);
}

<!-- Function to clear all filters -->
function clearFilters() {
SNC.canvas.interactiveFilters.removeDefaultValue(my_dashboardMessageHandler.Location_category, false);
my_dashboardMessageHandler.removeFilter();
}

<!-- Function to set and publish filters based on Location, Category and Sub-Category selections -->
function setFilters(){
var arrVal = [];
var locationVal = $j("#locationOptions").val();
var appliesToVal = $j("#appliesToOptions").val();
var categoryVal = $j("#categoryOptions").val();
var subCategoryVal = $j("#subcategoryOptions").val();
var countryVal = $j("#countryOptions").val();
var stateVal = $j("#stateOptions").val();
arrVal.push(locationVal);
arrVal.push(appliesToVal);
arrVal.push(categoryVal);
arrVal.push(subCategoryVal);
arrVal.push(countryVal);
arrVal.push(stateVal);
if(locationVal != "" || appliesToVal != "" || categoryVal != "" || subCategoryVal != "" || countryVal != "" || stateVal != ""){
publishMultipleFilters(arrVal.toString());
}
else{
clearFilters();
}

if(countryVal){
var campa= $j("#locationOptions").val();
var mega= $j("#countryOptions").val();
var countryRec1 = new GlideAjax('global.EthicsComplicanceRAGlobalAjax');
countryRec1.addParam('sysparm_name','averageCalculation');
countryRec1.addParam('sysparm_campaign',campa);
countryRec1.addParam('sysparm_region',mega);
countryRec1.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
$j("#itemsSelected").text(answer);
//alert(answer);
})}

}

<!-- Function to dynamically update category options onChange of Requirement Applies to -->
<!-- Function to dynamically update Countries options onChange of Mega Region -->
function setCountries(){
$j('#countryOptions').find('option').remove();
var megaRegion = $j("#locationOptions").val();
var countryRec = new GlideAjax('global.EthicsComplicanceRAGlobalAjax');
countryRec.addParam('sysparm_name','getLocationRef');
countryRec.addParam('sysparm_location', megaRegion);
countryRec.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var x = document.getElementById("countryOptions");
var optionAll = document.createElement("option");
optionAll.innerHTML = "-- All --";
optionAll.value = "";
x.appendChild(optionAll);
var countryArr = JSON.parse(answer);
//for(var i = 0; i &lt; countryArr.length; i++){
for(var i = 0 in countryArr){
var option = document.createElement("option");
option.innerHTML = countryArr[i];
option.value = i;
x.appendChild(option);
}
});


}
</script>
<g:evaluate var="jvar_location" jelly="true" object="true">var loc = new GlideRecord('x_ubte_ethics_an_0_ethics_compliance_risk_assessment_campaign');
loc.addEncodedQuery('state!=1^ORstate=NULL^work_end!=NULL');
loc.orderBy('sys_created_on');
loc.query();
loc;</g:evaluate>
<g:evaluate var="jvar_country" jelly="true" object="true">
var loc1 = new GlideRecord('cmn_location');
loc1.addEncodedQuery('u_type_of_location=mega region');
loc1.orderBy('name');
loc1.query();
loc1;</g:evaluate>

 


<table>
<tr>
<td class="table-col-1">
<label>${gs.getMessage("Campaign")}</label>
</td>
<td class="table-col-1">
<label>${gs.getMessage("Mega Region")}</label>
</td>
</tr>
<tr>
<td class="table-col-1">
<select class="custom-select select-box" name="locationOptions" id="locationOptions" onchange="setCountries();setFilters();" >
<option value="">${gs.getMessage('-- All --')}</option>
<j:while test="${jvar_location.next()}">
<option value="${jvar_location.getValue('sys_id')}">${jvar_location.getValue('short_description')}</option>
</j:while>
</select>
</td>
<td class="table-col-1">
<select class="custom-select select-box" name="countryOptions" id="countryOptions" onchange="setFilters();" >
<option value="">${gs.getMessage('-- All --')}</option>
<j:while test="${jvar_country.next()}">
<option value="${jvar_country.getValue('sys_id')}">${jvar_country.getValue('name')}</option>
</j:while>
</select>
</td>
<tr>
<td class="text-right">
<div id="itemsSelected">${jvar_res}</div>
</td>
</tr>

</tr>


</table>
</j:jelly>

1 REPLY 1

Anish Reghu
Kilo Sage
Kilo Sage

To modify the dynamic content script to display departments instead of mega region for the selected campaign, you will need to make the following changes:

  1. Replace all instances of u_mega_region with u_department.
  2. Replace all instances of document.ref_sn_compliance_authority_document.u_mega_region with document.ref_sn_compliance_authority_document.u_department.

For example, the following lines of code:

 

if (valArr[0] != '') {
authFilter = "u_mega_region=" + valArr[0];
citationFilter = "document.ref_sn_compliance_authority_document.u_mega_region=" + valArr[0];
}

 

should be modified to:

 

 

if (valArr[0] != '') {
authFilter = "u_department=" + valArr[0];
citationFilter = "document.ref_sn_compliance_authority_document.u_department=" + valArr[0];
}

 

 

This will replace the mega region filter with a department filter.

Kindly mark the response as Correct or Helpful.

Cheers,

Anish