How to pass values from script include to client script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2019 07:50 AM
I'm trying to get the Risk by using Script Include and Client Script.
Risk was already calculated in the table I just want the exact risk to be retrieved on that table based on the selected recoverabilty, impact, deployment etc.
I also try to put the answer on alert() function but it says the value of answer is null.
Here's my scripts:
1. Script Include
var RiskLookup = Class.create();
RiskLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApplicationRisk: function()
{
var types = this.getParameter('sysparm_changetype');
var businessCIs = this.getParameter('sysparm_business');
var serverCIs = this.getParameter('sysparm_server');
var impacts = this.getParameter('sysparm_impact');
var deployments = this.getParameter('sysparm_deploy');
var recovers = this.getParameter('sysparm_recover');
// if(types == 'Application'){
var businessCI = new GlideRecord('cmdb_ci_service');
businessCI.addQuery('name', businessCIs);
businessCI.query();
while(businessCI.next())
{
var type = new GlideRecord('u_risk_calculation');
type.addQuery('u_change_type', types);
type.addQuery('u_business_criticality', businessCI.busines_criticality);
type.addQuery('u_impact', impacts);
type.addQuery('u_deployment', deployments);
type.addQuery('u_recoverability', recovers);
type.query();
while(type.next()){
var appRiskCalc = {};
appRiskCalc.risk_app = type.u_risk.getDisplayValue() || '';
var data = new global.JSON().encode(appRiskCalc);
return data;
}
}
//}
},
//type: 'RiskLookup'
});​
2. Client Script:
function onChange(control, oldValue, newValue, isLoading)
{
var type = g_form.getValue('u_change_type');
var businessCI = g_form.getValue('u_business_ci');
var serverCI = g_form.getValue('u_related_ci');
var impact_scope = g_form.getValue('impact');
var deployment = g_form.getValue('u_deployment');
var recoverability = g_form.getValue('u_recoverability');
if(type && businessCI && serverCI && impact_scope && deployment && recoverability ){
var ga = new GlideAjax('RiskLookup');
ga.addParam('sysparm_name','getApplicationRisk');
ga.addParam('sysparm_changetype', type);
ga.addParam('sysparm_business', businessCI);
ga.addParam('sysparm_server', serverCI);
ga.addParam('sysparm_impact', impact_scope);
ga.addParam('sysparm_deploy', deployment);
ga.addParam('sysparm_recover', recoverability);
ga.getXML(getInfo);
}
function getInfo(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
alert(answer);
g_form.setValue('risk',answer.risk_app);
}
}
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2019 08:44 AM
I've never tested that idea, but for clarity sake (for developers that may come behind you) I wouldn't recommend it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2019 08:45 AM
Regardless of that though, if the value being passed in is a sys_id, name will never provide the desired record, lol.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2019 08:48 AM
I am passing these values of the fields below in script include:
var type = g_form.getValue('u_change_type');
var businessCI = g_form.getValue('u_business_ci');
var serverCI = g_form.getValue('u_related_ci');
var impact_scope = g_form.getValue('impact');
var deployment = g_form.getValue('u_deployment');
var recoverability = g_form.getValue('u_recoverability');
Single CI is what I need for Business CI.
In Server CI I'm gonna be needing multiple values since it will come from the List field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2019 09:03 AM
These are nearly all custom fields, so it's impossible for me to tell what you're passing in as values when all I have is the name of each field. I would suggest you add multiple gs.log() statements to your script include to see what each variable value is as the script is processed. Also put a log statement inside your next() construct to ensure the code is actually making it that far. If it is, log some more values to see what you're passing into your secondary GlideRecord call. Here's a quick and dirty setup:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2019 09:09 AM
Let me try this David. Thanks! Gimme a minute.