- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 06:15 AM
Hello, I have a drop down which is getting called by widget..
I have countries drop down and all the countries are in order whereas International is on top but I want it on the bottom of the list.. code is:
(function() {
data.category = $sp.getParameter('sys_id');
var otherCountries = gs.getProperty('sn_hr_sp.Other Countries').toString();
var userID = gs.getUserID();
var selectedCountryID = $sp.getParameter('country_id')||'';
if(selectedCountryID=='')
{
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id',userID);
userGR.query();
if(userGR.next())
{
selectedCountryID = userGR.getValue('u_core_country');
}
}
//include All and Global options
var countryArr = [
// {id: 'all', title: gs.getMessage("All")},
// {id: 'other', title: gs.getMessage("Other")}
//{id: 'other', title: gs.getMessage("Other countries")}
{id: 'international', title: gs.getMessage("International")}
];
data.selectedIndex =0;
// Get Accessible Countries Associated to Portal.
var portalGR = $sp.getPortalRecord();
var countryIDs = portalGR.getValue('u_countries');
data.countries = countryIDs.split(',');
data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "esc_sc_category";
var gr = new GlideRecord("core_country");
gr.addQuery('sys_id', 'IN', countryIDs);
gr.orderBy('name');
gr.query();
while(gr.next()){
var countrySysID = gr.getDisplayValue("sys_id");
var countryName = gr.getDisplayValue("name");
var countryObj = {id: countrySysID, title: countryName};
countryArr.push(countryObj);
}
//Set selected country to Other if users country is one of the 'Other' countries
if(otherCountries.indexOf(selectedCountryID) >= 0){
data.selectedIndex = 0;
data.countryName = countryArr[0].name;
}
//set selected country in country picker
var index = 0;
for(var i in countryArr){
//Find position of selected country in array
if (selectedCountryID == countryArr[i].id){
data.selectedIndex = index;
data.countryName = countryArr[i].name;
//gs.addInfoMessage(data.countryName);
}
index++;
}
data.countryArr = countryArr;
data.countryID=selectedCountryID;
})();
How can I make International get to bottom. We recently changed other countries to International.
TIA 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 06:31 AM
Try below code :
(function() {
data.category = $sp.getParameter('sys_id');
var otherCountries = gs.getProperty('sn_hr_sp.Other Countries').toString();
var userID = gs.getUserID();
var selectedCountryID = $sp.getParameter('country_id')||'';
if(selectedCountryID=='')
{
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id',userID);
userGR.query();
if(userGR.next())
{
selectedCountryID = userGR.getValue('u_core_country');
}
}
//include All and Global options
var countryArr = [];
data.selectedIndex =0;
// Get Accessible Countries Associated to Portal.
var portalGR = $sp.getPortalRecord();
var countryIDs = portalGR.getValue('u_countries');
data.countries = countryIDs.split(',');
data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "esc_sc_category";
var gr = new GlideRecord("core_country");
gr.addQuery('sys_id', 'IN', countryIDs);
gr.orderBy('name');
gr.query();
while(gr.next()){
var countrySysID = gr.getDisplayValue("sys_id");
var countryName = gr.getDisplayValue("name");
var countryObj = {id: countrySysID, title: countryName};
countryArr.push(countryObj);
}
var internationalCountry={id: 'international', title: gs.getMessage("International")};
countryArr.push(internationalCountry);
//Set selected country to Other if users country is one of the 'Other' countries
if(otherCountries.indexOf(selectedCountryID) >= 0){
data.selectedIndex = 0;
data.countryName = countryArr[0].name;
}
//set selected country in country picker
var index = 0;
for(var i in countryArr){
//Find position of selected country in array
if (selectedCountryID == countryArr[i].id){
data.selectedIndex = index;
data.countryName = countryArr[i].name;
//gs.addInfoMessage(data.countryName);
}
index++;
}
data.countryArr = countryArr;
data.countryID=selectedCountryID;
})();
Please mark answer as Correct or Helpful based on impact.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 06:31 AM
Try below code :
(function() {
data.category = $sp.getParameter('sys_id');
var otherCountries = gs.getProperty('sn_hr_sp.Other Countries').toString();
var userID = gs.getUserID();
var selectedCountryID = $sp.getParameter('country_id')||'';
if(selectedCountryID=='')
{
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id',userID);
userGR.query();
if(userGR.next())
{
selectedCountryID = userGR.getValue('u_core_country');
}
}
//include All and Global options
var countryArr = [];
data.selectedIndex =0;
// Get Accessible Countries Associated to Portal.
var portalGR = $sp.getPortalRecord();
var countryIDs = portalGR.getValue('u_countries');
data.countries = countryIDs.split(',');
data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "esc_sc_category";
var gr = new GlideRecord("core_country");
gr.addQuery('sys_id', 'IN', countryIDs);
gr.orderBy('name');
gr.query();
while(gr.next()){
var countrySysID = gr.getDisplayValue("sys_id");
var countryName = gr.getDisplayValue("name");
var countryObj = {id: countrySysID, title: countryName};
countryArr.push(countryObj);
}
var internationalCountry={id: 'international', title: gs.getMessage("International")};
countryArr.push(internationalCountry);
//Set selected country to Other if users country is one of the 'Other' countries
if(otherCountries.indexOf(selectedCountryID) >= 0){
data.selectedIndex = 0;
data.countryName = countryArr[0].name;
}
//set selected country in country picker
var index = 0;
for(var i in countryArr){
//Find position of selected country in array
if (selectedCountryID == countryArr[i].id){
data.selectedIndex = index;
data.countryName = countryArr[i].name;
//gs.addInfoMessage(data.countryName);
}
index++;
}
data.countryArr = countryArr;
data.countryID=selectedCountryID;
})();
Please mark answer as Correct or Helpful based on impact.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 11:58 AM
Thanks Mate for the quick response 🙂 It worked like a charm..