Advanced criteria in Custom greetings and Setup

Sathya10
Tera Expert

Hi All,

 

I'm configuring a custom greeting for a Retail customer that wants to shows different setup topics based on their user's location type (Store/Corporate/Warehouse). I'm trying to use the Advanced Condition mode and I have written the following script. 

 

 

(function executeCondition(/* glide record */ current) {  
	// customize condition logic here, return true or false
    var gr = new GlideRecord('cmn_location');
    gr.addQuery('sys_id',gs.getUser().getRecord().getValue('location'));
    gr.query();
    if(gr.next()){
                if(gr.cmn_location_type.getDisplayValue() == "Store"){
                    return true;
                }
                else
                    return false;
        }
})(current);

 

 

Testing this using the Test button does not seem to work as it is still going to the default greeting. Can someone tell me what I'm doing wrong and how to fix it ?

P.S: I have added gs.debug() to the script above as well, but it does not seem to log anything to the virtual agent testing log window. 

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Sathya10 

try this once

(function executeCondition(/* glide record */ current) {  
	// customize condition logic here, return true or false

	var userRec = new GlideRecord('sys_user');
	userRec.addQuery('sys_id', gs.getUserID());
	userRec.query();
	if(userRec.next()){
		if(userRec.location.cmn_location_type.getDisplayValue() == "Store")
			return true;
		else
			return false;
	}

})(current);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

Thank you very much for the response. But, it looks like the Advanced criteria is not working as expected. I used your script in the 3 different Custom Greeting & setup I have created for the 3 location types (Store/Corporate/Warehouse) by updating their respective values. But when I test it through service portal by impersonating end users from different locations, I'm not getting the promoted topics according to the setup. Is there a way I can enable logs and check which custom greeting is getting tagged to the user or if the advanced script is working as intended? 

Ramkumar Thanga
Mega Sage

Hi @Sathya10 

 

Is it possible to control the entire virtual agent to be enabled based on locations from the Advanced script. 

 

Thanks!

Ramkumar