Add IF/ELSE condition in Advanced Reference Qualifier

Suryansh Verma
Tera Contributor

Hello,

Is it possible to add the IF/ELSE condition in Advanced Reference Qualifier?

On the service portal, I have a Record Producer.

I want to put a condition that if (current.variables.u_name == current.opened_by) then call my script include into reference qualifier else it should work as a simple reference field.

I tried using the below but didn't work for me:

javascript:if(current.variables.u_name == current.opened_by){new ABC().ABCQuery(current.variables.date_day,gs.getUserID())}; else 'active=true';

In attributes field I put ref_qual_elements=u_name;opened_by

Is it possible to achieve this?

Thanks in advance.

1 ACCEPTED SOLUTION

You can try below:

Reference Qual: javascript: new ABC().ABCQuery(current.variables.date_day,gs.getUserID(),current.variables.u_name, current.opened_by)

 

In Script Include only in ABCQuery() function you can add 2 more parameters as above:

function:  ABCQuery( date,userSys_id,name,opened_by)

{

var sysID;

if (name == opened_by)

{

<code you have used currently in ABC Query()>

} else

{

var xyz = new GlideRecord(<table>);

xyz.addActiveQuery();

xyz.query();

while(xyz.next())

{

sysID.push(xyz.sys_id);

}

}

return sysID.join(',');

}

Something like this.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

6 REPLIES 6

AnubhavRitolia
Mega Sage
Mega Sage

Hi Suryanush,

Instead of checking that condition on Reference Qual, when not to use that condition on Script Include itself and based on that you can return the filtered record.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

You can try below:

Reference Qual: javascript: new ABC().ABCQuery(current.variables.date_day,gs.getUserID(),current.variables.u_name, current.opened_by)

 

In Script Include only in ABCQuery() function you can add 2 more parameters as above:

function:  ABCQuery( date,userSys_id,name,opened_by)

{

var sysID;

if (name == opened_by)

{

<code you have used currently in ABC Query()>

} else

{

var xyz = new GlideRecord(<table>);

xyz.addActiveQuery();

xyz.query();

while(xyz.next())

{

sysID.push(xyz.sys_id);

}

}

return sysID.join(',');

}

Something like this.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

@Anubhav Ritolia  - Thanks again for replying to my post.

I tried as per your suggestion but some error is coming up below is the code that I am using currently without any conditions.

Reference Qualifier:

javascript:new ABC().ABCQuery(current.variables.date_day,gs.getUserID());

Script Include:

var ABC= Class.create();

ABC.prototype = {
    initialize: function() {},

    ABC: function(selectedDate, user)

    {

        var arr = [];

        var usr = new GlideRecord('sys_user');

        usr.addQuery('sys_id', user);

        usr.query();

        if (usr.next())

        {

            var gr = new GlideRecord('x_sosb_fico_time_c_recorded_on_entries');

            gr.addQuery('u_date_day_1', selectedDate);

            gr.addQuery('u_name.user_name', usr.email);

            gr.query();

            while (gr.next())

            {


                arr.push(gr.u_ssp_code_1.toString());
                

            }

        }

        return "sys_idIN" + arr;
        

    },
    type: 'ABC'
};

 

Hi,

current wont work in Record Producer. try producer.date_day.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023