Help pulling info from Reference Field on Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 08:28 AM
Hello,
I have a record producer where the individual chooses an event to participate in on a reference field. Let's just say this field is "Event_Interested_In" which is mapped to the custom table "u_events". As they fill out the form I would like to write a on change client script for another field, lets say "phone" that it checks the event selected and if on that record "u_tshirts_provided" is "True" then a variable on the record producer is "u_tshirt_size" is changed to "true". Everything I have tried hasn't worked since you can't dot walk on the ui policy. Not sure since this is a producer if maybe I should be using variables somewhere?
Here is where I kinda left off
function onChange(control) {
// Since this is an onChange script, control will always be 'event_interested_in'
var selectedRecord = g_form.getReferenceRecord('event_interested_in'); // Get selected record from 'event_interested_in'
// Check if a record is selected and 'u_tshirts_provided' is true
if (selectedRecord && selectedRecord.u_t_shirts_provided == 'true') {
g_form.setValue('shirts', 'true');
} else {
g_form.setValue('shirts', '');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 08:35 AM
@Nic Omaha Please update your script as follows and check if it works for you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
// Since this is an onChange script, control will always be 'event_interested_in'
var selectedRecord = g_form.getReference('event_interested_in', eventCallback); // Get selected record from 'event_interested_in'
function eventCallback(selectedRecord) {
// Check if a record is selected and 'u_tshirts_provided' is true
if (selectedRecord && selectedRecord.u_t_shirts_provided == 'true') {
g_form.setValue('shirts', 'true');
} else {
g_form.setValue('shirts', '');
}
}
}