How to get the market unit

Dizy M
Tera Expert

Hi everyone!

I just want to know how to get the exact market unit by mapping the market unit field by getting the requestor's city and country ....

Im not sure where I got it wrong.

 

Field:

current.market_unit

 

getProfile.u_permcity = Requestor's City

getProfile.u_permcountry = Requestor's Country

 

So from the table "hr_profile", we need to get the value of "Requestor's city" and "Requestor's Country". After getting the requestor's city and country, we need to search the city and country in "cmn_location" table, then get the market unit value in "cmn_location"  and display it in "current.market_unit".

 

var getProfile = new GlideRecord('hr_profile');
	getProfile.addQuery('user', requestor);
	getProfile.query();

	if(getProfile.next()){
		current.permanent_city = getProfile.u_permcity;
		current.permanent_state_province = getProfile.u_permstate;
		current.permanent_zip_postal_code = getProfile.u_permpostal;
		current.market_unit = this.returnRegion(getProfile.u_permcity);
	}

function returnRegion(city) {
	var region = '';
	var country = this.getParameter(getProfile.u_permcountry);
	
	var getRegion = new GlideRecord('cmn_location');
	getRegion.addQuery('u_usgtype', 'City');
	getRegion.addQuery('u_country', country);
	getRegion.addQuery('nameSTARTSWITH', city);
	getRegion.query();
	if (getRegion.next()) {
		region = getRegion.u_market_unit;
	}
	return region;
}

 Thanks in advance!

1 REPLY 1

Tushar
Kilo Sage
Kilo Sage

Hi @Dizy M 

 

I hope this helps - 

var getProfile = new GlideRecord('hr_profile');
getProfile.addQuery('user', requestor);
getProfile.query();

if (getProfile.next()) {
    current.permanent_city = getProfile.u_permcity;
    current.permanent_state_province = getProfile.u_permstate;
    current.permanent_zip_postal_code = getProfile.u_permpostal;
    current.market_unit = returnRegion(getProfile.u_permcity, getProfile.u_permcountry);
}

function returnRegion(city, country) {
    var region = '';
    
    var getRegion = new GlideRecord('cmn_location');
    getRegion.addQuery('u_usgtype', 'City');
    getRegion.addQuery('u_country', country);
    getRegion.addQuery('name', city);
    getRegion.query();
    
    if (getRegion.next()) {
        region = getRegion.u_market_unit;
    }
    return region;
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar