g_form.getParameter('sysparm_id'); not supported in service portal

ARNAB3
Giga Expert

_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]);
}
}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

parse the URL and get the value of sys_id parameter

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@ARNAB 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@ARNAB 

I believe you should mark the response which has script/solution so that it helps future readers

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader