from users email, i want contacts account locations

Community Alums
Not applicable

I have created one record Producer, which consists of two Variables, one is requestor_name and the other one is meeting_event_location.

The Requestor_name is referring to sys_user table and the meeting_event_location referring to cmn_location table

I want that from user email, i want to fetch the contact account locations, i have written the below script include for that, but its not working. can someone please help me why this script is not working, this script is working for logged in user, how i can make for all users?

 

accountLocation: function(d)
{
var user = new GlideRecord('sys_user');
        user.get(gs.getUserID());
 
var contact = new GlideRecord('customer_contact');
contact.addQuery('email', user.email);
contact.query();
 
if(contact.next()){
 
var cont = contact.getValue('sys_id');
}
 
var locationlist = [];
        var loclist = new GlideRecord('cmn_location');
        loclist.addEncodedQuery('account.u_corporate_account'+d.cont.account);
        loclist.query();
        while (loclist.next()) {
            locationlist.push(loclist.getValue('sys_id'));
        }
        return 'sys_idIN' + locationlist;
 
 
},
 
And i am using Advanced reference qualifier in variable (meeting_event_location)
 
the reference qualifier is = javascript:new sn_customerservice.locationlist().accountLocation(current)
2 REPLIES 2

umaaggarwal
Giga Guru
Giga Guru

Hi,

 

Please try passing the value instead current while you call your script include

 

 javascript&colon;new sn_customerservice.locationlist().accountLocation(current.variables.<userVariable>)

 

This would take sys id if the user selected un user field and pass the same to your script include so that you do not have to use logged in user, instead you can use the user you have passed from the variable.

 

Rest all should work fine.

Harish Bainsla
Tera Sage
Tera Sage

var LocationListScript = Class.create();

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

accountLocation: function(userEmail) {
var contact = new GlideRecord('customer_contact');
contact.addQuery('email', userEmail);
contact.query();

if (contact.next()) {
var accountId = contact.getValue('account');
var locationlist = [];
var loclist = new GlideRecord('cmn_location');
loclist.addQuery('account', accountId);
loclist.query();

while (loclist.next()) {
locationlist.push(loclist.getValue('sys_id'));
}

return 'sys_idIN' + locationlist.join(',');
}

return ''; // Return an empty string if no locations are found
},

type: 'LocationListScript'
};

 

and it in reference Qualifier

javascript&colon;new LocationListScript().accountLocation(gs.getUser().getEmail())