- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 09:07 AM
_form.getParameter('sysparm_id'); - not working in portal what should be the alternate way to prevent error in portal.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading ) {
return;
}
var item = g_form.getParameter('sysparm_id');
var bf = g_form.getValue('business_function');
g_form.clearOptions('u_short_description');
if (newValue == '') {return;}
var encoded = 'u_active=true^u_catalog_item='+item+'^u_business_function='+bf+'^u_subcategory='+newValue;
var tablename = 'u_bs_to_it_field_level_routing';
// now bring back every row in the table that matches our criteria
var roleData = new GlideAjax('DataAjaxUtil');
roleData.addParam('sysparm_name','getResultSet');
roleData.addParam('sysparm_encoded_query',encoded);
roleData.addParam('sysparm_table_name',tablename);
roleData.getXMLWait();
var roleArr = roleData.getAnswer();
if (!roleArr)
return;
roleArr = JSON.parse(roleArr);
var opt = [];
g_form.setDisplay('u_short_description' , true);
g_form.setMandatory('u_short_description' , true);
g_form.addOption('u_short_description', "", " --None-- ");
//now get a unique listing of these short descriptions
for (var i = 0; i < roleArr.length; i++) {
if (opt.indexOf(roleArr[i].u_short_description) == -1) {
opt.push(roleArr[i].u_short_description);
}
}
// now sort them and present them in the drop down choices.
opt.sort();
for ( i = 0; i < opt.length; i++) {
g_form.addOption('u_short_description' , opt[i] , opt[i]);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 09:12 AM
Hi,
updated script
Ensure: Isolate Script field for this client script is set to false
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading ) {
return;
}
var item;
if(window != null){
// native
item = g_form.getParameter('sysparm_id');
}
else{
// portal
var url = top.location.href;
item = new URLSearchParams(url).get("sys_id");
}
var bf = g_form.getValue('business_function');
g_form.clearOptions('u_short_description');
if (newValue == '') {return;}
var encoded = 'u_active=true^u_catalog_item='+item+'^u_business_function='+bf+'^u_subcategory='+newValue;
var tablename = 'u_bs_to_it_field_level_routing';
// now bring back every row in the table that matches our criteria
var roleData = new GlideAjax('DataAjaxUtil');
roleData.addParam('sysparm_name','getResultSet');
roleData.addParam('sysparm_encoded_query',encoded);
roleData.addParam('sysparm_table_name',tablename);
roleData.getXMLWait();
var roleArr = roleData.getAnswer();
if (!roleArr)
return;
roleArr = JSON.parse(roleArr);
var opt = [];
g_form.setDisplay('u_short_description' , true);
g_form.setMandatory('u_short_description' , true);
g_form.addOption('u_short_description', "", " --None-- ");
//now get a unique listing of these short descriptions
for (var i = 0; i < roleArr.length; i++) {
if (opt.indexOf(roleArr[i].u_short_description) == -1) {
opt.push(roleArr[i].u_short_description);
}
}
// now sort them and present them in the drop down choices.
opt.sort();
for ( i = 0; i < opt.length; i++) {
g_form.addOption('u_short_description' , opt[i] , opt[i]);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 09:10 AM
Hi,
parse the URL and get the value of sys_id parameter
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 09:12 AM
Hi,
updated script
Ensure: Isolate Script field for this client script is set to false
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading ) {
return;
}
var item;
if(window != null){
// native
item = g_form.getParameter('sysparm_id');
}
else{
// portal
var url = top.location.href;
item = new URLSearchParams(url).get("sys_id");
}
var bf = g_form.getValue('business_function');
g_form.clearOptions('u_short_description');
if (newValue == '') {return;}
var encoded = 'u_active=true^u_catalog_item='+item+'^u_business_function='+bf+'^u_subcategory='+newValue;
var tablename = 'u_bs_to_it_field_level_routing';
// now bring back every row in the table that matches our criteria
var roleData = new GlideAjax('DataAjaxUtil');
roleData.addParam('sysparm_name','getResultSet');
roleData.addParam('sysparm_encoded_query',encoded);
roleData.addParam('sysparm_table_name',tablename);
roleData.getXMLWait();
var roleArr = roleData.getAnswer();
if (!roleArr)
return;
roleArr = JSON.parse(roleArr);
var opt = [];
g_form.setDisplay('u_short_description' , true);
g_form.setMandatory('u_short_description' , true);
g_form.addOption('u_short_description', "", " --None-- ");
//now get a unique listing of these short descriptions
for (var i = 0; i < roleArr.length; i++) {
if (opt.indexOf(roleArr[i].u_short_description) == -1) {
opt.push(roleArr[i].u_short_description);
}
}
// now sort them and present them in the drop down choices.
opt.sort();
for ( i = 0; i < opt.length; i++) {
g_form.addOption('u_short_description' , opt[i] , opt[i]);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 10:19 AM
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
If not, please let us know if you need some more assistance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 02:06 AM