Catalog Item form - prepopulate fields with street address, city & postal code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 03:30 AM
1. I have the following simple form looking like this:
2. What i need is the fields to be populated with the current users location street address, postal code and city.
How ever the location field is referring to another table called Building [u_buildings] where the fields i want is.
3. I have the following simple form looking like this:
4. The variable set contains 3 variables
5. For the "delivery_adress" i've chosen type "Reference" and referring to the table Building [u_building] and narrow it down to country Sweden.
6. What i then get is the building (names) in Sweden, but what i would need is to have it prepopulated with the buildings Street Address. In this case for this user it should be Arboga's street address ("Centrumleden 11|732 30 Arboga|Sweden").
How can i achieve this, best regards Karl
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 10:56 AM
A couple questions
- Why are you using a custom table for locations instead of the location table referenced by the sys_user table? You can even add custom fields if needed.
- How is a user related to a location in your custom building table? Is there another location field you created on the user table to link a user to a u_building or does the out of box location table reference the u_building table? I feel there has to be some link between the user and the location.
Possible solution
Depending on the answer above you would run an onload client script that does a glide ajax call to a script include. That script include would do several things.
- Query the current users record
- Dot walk to its location ( however you are setting up this relationship between user and u_building )
- Store the information in an object that stores the required information.
- Use JSON.stringify to return this object.
- Returns the information to your onload client script.
Then your client script will parse this object and you set the values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 10:59 AM
This may help if you are new to glideajax and plan on using it. Unless I misunderstood the question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 11:08 AM
I use an on-change client script on my catalog items to do this. But I'm doing it based on the person they add to the access_for field. You should be able to change the var caller line (line 5) to something to to pull the currently logged in user. I'm not sure exactly how to call that but I know it can be done.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference('access_for', doAlert);
function doAlert (caller){
g_form.setValue('email_for', caller.email.toString());
g_form.setValue('userid', caller.user_name.toString());
g_form.setValue('business_phone', caller.phone.toString());
g_form.setValue('mobile_phone', caller.mobile_phone.toString());
g_form.setValue('supervisor_approver', caller.manager.toString());
}}