Need to set Default value for an Advanced Qualifier reference variable

Rashim Walia
Tera Contributor

Hi,

 

I need to fetch Service Offerings subscribed by the User's company from the table service_subscribe_company. I have used the Adavanced Qualifier to fetch the values and its working fine (Below screenshot for reference)

RashimWalia_1-1671659570893.png

My requirement is to set the default value if only one Service Offering is subscribed by the company.

 

I have tried to achieve this by Catalog Client script or the Default value in the Reference field but neither of them is working. Can anybody help me to achieve this functionality please?

 

Your help will be greatly appreciated , Thanks!!

7 REPLIES 7

Right.you need a script include.

Following is an example

https://www.servicenow.com/community/developer-forum/how-to-use-glideaggregate-in-client-script/m-p/...

 


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv,

 

I have written the below script include but still its returning null all the time. Could you please see if I am doing anything wrong here

 

var ServiceOfferingSubscribed = Class.create();
ServiceOfferingSubscribed.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{
//initialize: function() {},

checkServiceOfferingName: function () {
//For each subscribed company, grab the names of the list of Service Offerings and compare to the name parameter passed into this function
var company = this.getParameter('sysparm_company');
var scount = 0;
var gr = new GlideRecord('service_subscribe_company');
gr.addQuery('core_company', gs.getUser().getCompanyID());
gr.addQuery('service_offering','b951767edb6be34047f758b8e');
gr.addQuery('service_offering','8e21dc571be79dd02c4962b5a');
gr.query();
while (gr.next())
{
scount++;
}
if (scount==1)
{
alert(gr.service_offering); //return into CS
}
else
{
alert('Multiple');
}
},
type: 'ServiceOfferingSubscribed'
});

Could you please confirm if client callable is checked in script include?

Also use the following. This function return the sysid if it is one record else returns null. In client script you can set the value of the field

var ServiceOfferingSubscribed = Class.create();
ServiceOfferingSubscribed.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{
//initialize: function() {},

checkServiceOfferingName: function () {
//For each subscribed company, grab the names of the list of Service Offerings and compare to the name parameter passed into this function
var company = this.getParameter('sysparm_company');
var scount = 0;
var cmp = '';
var gr = new GlideRecord('service_subscribe_company');
gr.addQuery('core_company', gs.getUser().getCompanyID());
gr.addQuery('service_offering','b951767edb6be34047f758b8e');
gr.addQuery('service_offering','8e21dc571be79dd02c4962b5a');
gr.query();
while (gr.next())
{
scount++;
cmp = gr.sys_id;
}
if (scount==1)
{
 return cmp;
}
else
{
return '';
}
},
type: 'ServiceOfferingSubscribed'
});

 


Please mark this response as correct or helpful if it assisted you with your question.