g_form.getParameter is not a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2018 09:10 AM
I am going through testing for Kingston to make sure all items dont get javascript errors. I am getting an error for an error that worked on the CMS but not Service Portal. I am not a developer so I am not sure how to replace this code for it to work.
Build- Kingston
Catalog Client Script - OnLoad
Purpose of script...custom fields are on the catalog item for IT Risk approval or funding required. The script checks that and populates a message if it is true for that item.
I get the following Error in Developer Tools on Google
js_includes_sp.jsx?v=04-25-2018_0907&lp=Tue_May_08_11_36_12_PDT_2018&c=17_294:67075 (g_env) [SCRIPT:EXEC] Error while running Client Script "get Cat Item control fields": TypeError: g_form.getParameter is not a function
function onLoad() {
var myItem = g_form.getParameter("sysparm_id");
var ga = new GlideAjax('SoftwareReqControlUtil');
ga.addParam('sysparm_name', 'getSoftwareControlFields');
ga.addParam('sysparm_item', myItem);
ga.getXML(getItemSelected);
}
function getItemSelected(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//g_form.addInfoMessage(answer); //JSON String
answer = answer.evalJSON(); //Transform the JSON string to an object
g_form.setValue('funding_required', answer[0].fundingReq);
if (answer[0].fundingReq == 'true') {
g_form.addInfoMessage('The selected Software requires funding');
}
g_form.setValue('it_risk_review_required', answer[0].itRisk);
if (answer[0].itRisk == 'true') {
g_form.addInfoMessage('The selected Software requires IT RISK Review');
}
g_form.setValue('standard_software', answer[0].standard);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2018 11:51 AM
Weird. Using my last bit of code exactly (with the getParameterValue function instead), it should be working, at least per Brad's previous Community post I linked.
If you use this instead, does anything appear under System Logs -> script log statements for your "myitem" variable? (Look for something around the time you would have run your script. My addition this time was a gs.log(); statement to capture whatever value your "myItem" variable is being passed. (It should be like a 20-something + hexadecimal value.)
function onLoad() {
//Use the 'getParameterValue' function below to get the parameter values from the URL
var myItem = getParameterValue('sysparm_id');
gs.log(myItem);
var ga = new GlideAjax('SoftwareReqControlUtil');
ga.addParam('sysparm_name', 'getSoftwareControlFields');
ga.addParam('sysparm_item', myItem);
ga.getXML(getItemSelected);
}
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(top.location);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}
function getItemSelected(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//g_form.addInfoMessage(answer); //JSON String
answer = answer.evalJSON(); //Transform the JSON string to an object
g_form.setValue('funding_required', answer[0].fundingReq);
if (answer[0].fundingReq == 'true') {
g_form.addInfoMessage('The selected Software requires funding');
}
g_form.setValue('it_risk_review_required', answer[0].itRisk);
if (answer[0].itRisk == 'true') {
g_form.addInfoMessage('The selected Software requires IT RISK Review');
}
g_form.setValue('standard_software', answer[0].standard);
}