Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reference Qualifier pass value to the script include

Don Dom
Tera Contributor

Hello

 

I would like to put reference qualifier on field (2)

DonDom_0-1713426874780.png

Based on value from field (1)

Unfortunately field (1) it's sys_id because it's reference from other table.

 

<u_type display_value="Responsibility">281c2a33875d8a50aacccaec0ebb357e</u_type>

<u_gime display_value="Senior Managers">6f2b6a77871d8a50aacccaec0ebb35bb</u_gime>

 

My Reference Qualifier looks like this:

DonDom_1-1713427093805.png

 

Script Include like this:

 

gs.info('WWW REQ FULL START');

var uGime = 'u_gime';

var hr_RefQuaSMCRUtils = Class.create();

hr_RefQuaSMCRUtils.prototype = {

    initialize: function(u_gime) {},

    smcrObligationType: function() {

        var ObligationTypeCheck = new GlideRecord('sn_hr_core_wwww_type');

        ObligationTypeCheck.addQuery('u_gime',u_gime);

        ObligationTypeCheck.query();

        gs.info('WWW REQ how much: '+ObligationTypeCheck.getRowCount());

        var obligationTypeListy = [];

        while(ObligationTypeCheck.next()){

            obligationTypeListy.push(ObligationTypeCheck.getUniqueValue());


        }

        gs.info('WWW ID: '+obligationTypeListy.toString());

        return 'sys_idIN'+obligationTypeListy.toString();


    },

    type: 'hr_RefQuaSMCRUtils'

};

 

But I always got this error:

 

com.glide.script.RhinoEcmaError: "u_gime" is not defined.
sys_script_include.b69a2b9a97258e54e59cf5fce053af75.script : Line(2) column(0)
1: gs.info('WWW REQ FULL START');
==> 2: gs.info('WWW REQ u_gime: '+u_gime);
3: var uGime = 'u_gime';
4: var hr_RefQuaSMCRUtils = Class.create();
5: hr_RefQuaSMCRUtils.prototype = {

 

Generally I need to filter values in (2) based on what was choosed in field (1).

Any idea pls how to pass sys_id to scipt include and work with sys_id there ?

thx for info.

2 ACCEPTED SOLUTIONS

Ranjit Nimbalka
Mega Sage

Hi @Don Dom 

 

1. You are passing parameter to initialize function but you are calling function is smcrObligationType so you need to pass parameter here.

please try using below script:-

var hr_RefQuaSMCRUtils = Class.create();

hr_RefQuaSMCRUtils.prototype = {

    initialize: function() {},

    smcrObligationType: function(u_gime) {

        var ObligationTypeCheck = new GlideRecord('sn_hr_core_wwww_type');

        ObligationTypeCheck.addQuery('u_gime',u_gime);

        ObligationTypeCheck.query();

        gs.info('WWW REQ how much: '+ObligationTypeCheck.getRowCount());

        var obligationTypeListy = [];

        while(ObligationTypeCheck.next()){

            obligationTypeListy.push(ObligationTypeCheck.getUniqueValue());


        }

        gs.info('WWW ID: '+obligationTypeListy.toString());

        return 'sys_idIN'+obligationTypeListy.toString();


    },

    type: 'hr_RefQuaSMCRUtils'

};

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit

View solution in original post

Community Alums
Not applicable

 

Hi @Don Dom ,

Can you please try below script

gs.info('WWW REQ FULL START');

var uGime = 'u_gime';

var hr_RefQuaSMCRUtils = Class.create();

hr_RefQuaSMCRUtils.prototype = {

    initialize: function(uGime) {},

    smcrObligationType: function() {

        var ObligationTypeCheck = new GlideRecord('sn_hr_core_wwww_type');

        ObligationTypeCheck.addQuery('u_gime',uGime);

        ObligationTypeCheck.query();

        gs.info('WWW REQ how much: '+ObligationTypeCheck.getRowCount());

        var obligationTypeListy = [];

        while(ObligationTypeCheck.next()){

            obligationTypeListy.push(ObligationTypeCheck.getUniqueValue());


        }

        gs.info('WWW ID: '+obligationTypeListy.toString());

        return 'sys_idIN'+obligationTypeListy.toString();


    },

    type: 'hr_RefQuaSMCRUtils'

};

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

View solution in original post

7 REPLIES 7

Anubhav24
Mega Sage

Hi @Don Dom ,

While passing the value to your script inlcude in your reference qualifier , can you pass value like this current.u_gime this will automatically pass sys_id.

Also could you please ecplain what is the significance of this statement 

var uGime = 'u_gime';

I would suggest if you are storing value, try to store that which is not exactly the same name as your table column.

Please mark helpful/correct if my response helped you.

I do not know to be honest. I got this error

 

com.glide.script.RhinoEcmaError: "u_gime" is not defined.
sys_script_include.b69a2b9a97258e54e59cf5fce053af75.script : Line(2) column(0)
1: gs.info('WWW REQ FULL START');
==> 2: gs.info('WWW REQ u_gime: '+u_gime);
3: var uGime = 'u_gime';

 So I'm "lost" what is wrong in the Script Include 😞

Ranjit Nimbalka
Mega Sage

Hi @Don Dom 

 

1. You are passing parameter to initialize function but you are calling function is smcrObligationType so you need to pass parameter here.

please try using below script:-

var hr_RefQuaSMCRUtils = Class.create();

hr_RefQuaSMCRUtils.prototype = {

    initialize: function() {},

    smcrObligationType: function(u_gime) {

        var ObligationTypeCheck = new GlideRecord('sn_hr_core_wwww_type');

        ObligationTypeCheck.addQuery('u_gime',u_gime);

        ObligationTypeCheck.query();

        gs.info('WWW REQ how much: '+ObligationTypeCheck.getRowCount());

        var obligationTypeListy = [];

        while(ObligationTypeCheck.next()){

            obligationTypeListy.push(ObligationTypeCheck.getUniqueValue());


        }

        gs.info('WWW ID: '+obligationTypeListy.toString());

        return 'sys_idIN'+obligationTypeListy.toString();


    },

    type: 'hr_RefQuaSMCRUtils'

};

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit

thank you so much 🙂