How can I call a Script Include from a BR, and return a value to use in the BR?

truzicki
Kilo Expert

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.

1 ACCEPTED SOLUTION

Abinaya
Mega Expert

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 ;


View solution in original post

6 REPLIES 6

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.


Aman33
Kilo Explorer

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.

find_real_file.png

 

variable 'result' is blank always.