The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How do you autofill and concatenate location table field values in a record producer for a user?

alexsheer
Kilo Contributor

Does anyone know how to script this? Been at it for a while and can't figure it out.

Currently on the sys_user table there is a location reference field. This field has a 3 digit location ID. Upon clicking the info button next to this field, it redirects to the cmn_location table that has the address fields for that user that they require.

I created a record producer, and need to set the default value of a single line text field with the concatenated values of the current requested for user's address upon load. The fields I require from the cmn_location table are: street, city, state, zip and country.

After this loads successfully, whenever the requested for user is changed, I need to auto populate this same single line text field with the concatenated location values of whichever other user is selected. It needs to be a single line text field since the customer wants this address field to be editable. 

I've tried making an onChange catalog script on the record producer but can't seem to make it work, nor can I figure out how to set the default value. I'm not that great with javascript, if anyone can lend a hand, I'd really appreciate it!

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

On the text field, you can set the Default field in the variable dictionary and call a class less script.

In the default field write javascript: getUserAddress()

 

The script include name can be 

getUserAddress

 

in script should be 

 

function getUserAdderss()

{

var user = new GlideRecord('sys_user');
user.get(gs.getUserID())

return user.name+','+user.street+','+user.city+','+user.zip+','+user.zip;

}

 

Let me know, if this works, then we can work on the onChange script


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

View solution in original post

9 REPLIES 9

SanjivMeher
Kilo Patron
Kilo Patron

On the text field, you can set the Default field in the variable dictionary and call a class less script.

In the default field write javascript: getUserAddress()

 

The script include name can be 

getUserAddress

 

in script should be 

 

function getUserAdderss()

{

var user = new GlideRecord('sys_user');
user.get(gs.getUserID())

return user.name+','+user.street+','+user.city+','+user.zip+','+user.zip;

}

 

Let me know, if this works, then we can work on the onChange script


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

Thanks for the advice Sanjiv! I got the address field to load using the script include you recommended, this was the code i used:

 

function getUserAddress()
{
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
return user.getDisplayValue('location.street')+', '+user.getDisplayValue('location.city')+', '+user.getDisplayValue('location.state')+', '+user.getDisplayValue('location.zip')+', '+user.getDisplayValue('location.country') ;

}

 

My only question is now how do I call this function in an onChange catalog client script? 

In the onchange, try with belo script

 

var user = new GlideRecord('sys_user');
user.get(g_user.UserID);

var loc = new GlideRecord('cmn_location');

loc.get(user.location);

var loc =  loc.street+', '+loc.city+', '+loc.state+', '+loc.zip+', '+loc.country;

g_form.setValue('your location field',loc);


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

The correct location field is changing however all the values are coming back undefined. This was the code I used:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var user = new GlideRecord('sys_user');
user.get(g_user.UserID);
var loc = new GlideRecord('cmn_location');
loc.get(user.location);
var locfield = loc.street+', '+loc.city+', '+loc.state+', '+loc.zip+', '+loc.country;
g_form.setValue('lease_refresh_hardware_request_location_of_end_user_for_delivery',locfield);

}