- 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:07 AM
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.
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: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:28 AM
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'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:41 AM
Hi,
current wont work in Record Producer. try producer.date_day.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023