- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 01:41 AM
Greetings, everyone. I'm trying to call a script include from a business rule, and return a value to the BR to use in updating a record. My goal is to search for the value of a field (in this case "u_ad_department" in the sys_user table) in a table that contains aliases and a "normalized" value. Then, I want to update another field (in this case the department field in the sys_user table) with the "normalized" value. Here's what I've got so far:
The BR is:
var gr = new ABCNormalization();
gr.getNormalization(current.u_ad_department, 'cmn_department', 'DEPARTMENT');
current.department = answer;
And the script include is:
var ABCNormalization = Class.create();
ABCNormalization.prototype = {
initialize: function() {
},
getNormalization: function(alias, table, label) {
var tableID = '';
var grTable = new GlideRecord('sys_db_object');
grTable.addQuery('name', table);
grTable.query();
while (grTable.next()) {
tableID = grTable.sys_id;
}
var returnText = 'NOT NORMALIZED ' + label;
var grAlias = new GlideRecord('u_abc_normalization_aliases');
grAlias.addQuery('u_alias', alias);
grAlias.addQuery('u_table', tableID);
grAlias.query();
while (grAlias.next()) {
returnText = grAlias.u_normalized_value.getDisplayValue();
}
return returnText;
},
type: 'ABCNormalization'
};
Calling the Script Include works, and the Script Include itself works (I've sprinkled a few gs.log statements throughout). But, I can't get the value I want to come back to the Business Rule so that I can use it.
Can anyone point out where I've wandered off the ranch?
Thank you!
-Tim.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 01:55 AM
Hi Tim,
If your working fine, in that case you have to just initialize a variable and call the function within your script include:
Use the following code:
var gr = new ABCNormalization();
var returnVal = gr.getNormalization(current.u_ad_department, 'cmn_department', 'DEPARTMENT');
current.department = returnVal ;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 12:38 PM
That's what those temporary variables are good for Tim. You can see "Did I get A when I expected A..." then go back and optimize once everything is working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 02:07 AM
Hi,
I have tried this but it is not working for me, I'm working in scoped Application.
I have created a object of Script include with variable 'si'
and calling a function of that script include,
that function should return sysid of a record but it is blank.
I have certain that I'm getting sysid in script include.
variable 'result' is blank always.