Multiple function script include not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2022 06:26 AM
Hi all,
I'm hoping someone can point me in the right direction with this. Bearing in mind I'm new(ish) to scripting, I'm having trouble making a script include work as soon as I put more than one function in it. E.g below:
var esgUtils2 = Class.create();
esgUtils2.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getCozInfo: function () {
var model = this.getParameter('sysparm_model');
var eMod = new GlideRecord('x_ka2_esg1_esg_core');
eMod.addQuery('model', model);
eMod.query();
if (eMod.next()){
var newmodel = this.getParameter('sysparm_newmodel');
var nMod = new GlideRecord('x_ka2_esg1_esg_core');
nMod.addQuery('model', newmodel);
nMod.query();
if (nMod.next()){
var results = {
"CurrEmPerAsset": eMod.getValue("asset_emissions"),
"CurrCozYears": eMod.getValue("asset_life_in_years"),
"NewEmPerAsset": nMod.getValue("asset_emissions"),
"NewCozYears": nMod.getValue("asset_life_in_years"),
"RecEm": eMod.getValue("asset_recycling_emissions"),
"CombEm": eMod.getValue("asset_emission_total"),
"AssetKg": eMod.getValue("asset_emission_kg"),
"RecKg": eMod.getValue("asset_recycling_emission_kg"),
"CombKg": eMod.getValue("asset_emission_total_kg"),
"AveWt": eMod.getValue("kg_average_weight"),
};
return JSON.stringify(results);
}
}
}
getModelAm: function () {
var count = 0;
var model = this.getParameter('sysparm_model');
var cMod = new GlideRecord('alm_hardware');
cMod.addQuery('model', model);
cMod.query();
while (cMod.next()){
count += 1;
}
var results = {
"amount": count,
};
return JSON.stringify(results);
}
// type: 'esgUtils2'
});
If I put them in separate script includes they work fine. I'm hoping I'm missing something really simple!! Any pointers please?
Thank you!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2022 07:49 AM
Hi
Every function in a script include has to be separated by commas(,). Simply by adding comma, your functions should be error free.
Copy/Paste the below code and it should work.
var esgUtils2 = Class.create();
esgUtils2.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getCozInfo: function() {
var model = this.getParameter('sysparm_model');
var eMod = new GlideRecord('x_ka2_esg1_esg_core');
eMod.addQuery('model', model);
eMod.query();
if (eMod.next()){
var newmodel = this.getParameter('sysparm_newmodel');
var nMod = new GlideRecord('x_ka2_esg1_esg_core');
nMod.addQuery('model', newmodel);
nMod.query();
if (nMod.next()){
var results = {
"CurrEmPerAsset": eMod.getValue("asset_emissions"),
"CurrCozYears": eMod.getValue("asset_life_in_years"),
"NewEmPerAsset": nMod.getValue("asset_emissions"),
"NewCozYears": nMod.getValue("asset_life_in_years"),
"RecEm": eMod.getValue("asset_recycling_emissions"),
"CombEm": eMod.getValue("asset_emission_total"),
"AssetKg": eMod.getValue("asset_emission_kg"),
"RecKg": eMod.getValue("asset_recycling_emission_kg"),
"CombKg": eMod.getValue("asset_emission_total_kg"),
"AveWt": eMod.getValue("kg_average_weight"),
};
return JSON.stringify(results);
}
}
},
getModelAm: function() {
var count = 0;
var model = this.getParameter('sysparm_model');
var cMod = new GlideRecord('alm_hardware');
cMod.addQuery('model', model);
cMod.query();
while (cMod.next()){
count += 1;
}
var results = {
"amount": count,
};
return JSON.stringify(results);
},
type: 'esgUtils2'
});
Hope this helps you