- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:02 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:16 AM
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.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:47 AM
Reference Qualifier:
javascript:new ABC().ABCQuery(producer.date_day,gs.getUserID(),producer.u_name,producer.opened_by);
Script Include:
var ABC= Class.create();
ABC.prototype = {
initialize: function() {},
ABC: function(selectedDate, user,name,opened_by)
{
var arr = [];
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', user);
usr.query();
if (usr.next())
{
if(name!=opened_by)
{
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());
}
} else {
var gr = new GlideRecord('x_sosb_fico_time_c_recorded_on_entries');
gr.addActiveQuery();
gr.query();
while (gr.next())
{
arr.push(gr.u_ssp_code_1.toString());
}
}
}
return "sys_idIN" + arr;
},
type: 'ABC'
};
Try this.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:34 AM
Hi,
current.opened_by won't work in ref qualifier
your reference variable is referring to which table?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader