Hi,
I am trying to populate several textfields based on the results of a reportQuery that uses input from a select field.
The form:
form id = form_1
select id = userids | displays all available userids. The user selects one.
onChange = ca_fd.js.onChangeUserid();
Report/Plug-in Variabel = $({'user_ids':ca_fdGetSelectedOptionValues(ca_fd.formId,'userids')[0]})
Report/Plug-in Id = 9446bcf476c836e9439a91592ae373a1-70e31482916835192
textfield id = email_addr | Autopopulate the email address of the selected user.
textfield 2 id = pnumber | Autopopulate the phone number of the selected user.
Data object:
A data object populates the selectbox with all available userids with the following query:
id: 9446bcf476c836e9439a91592ae373a1-70e31482916835192
table: ca_contact
Query: select userid as id, userid, email_address, pri_phone_number from ca_contact where userid like '%user_ids%%%'
a runtime variable user_ids has been created, containing a string value.
The script created locally for the form:
{
onChangeUserid : function() {
ca_fd.js.setInfo();
},
setInfo : function() {
var user_ids = {value:ca_fdGetSelectedOptionValues(ca_fd.formId, 'userids')};
console.log(user_ids.value); // returns an array containing the one userid specified in the selectbox.
ca_reportQuery('9446bcf476c836e9439a91592ae373a1-70e31482916835192', {userids:user_ids.value}, ca_fd.js.onSuccess, ca_fd.js.onFailure);
},
onSuccess : function(result) {
if (result.length == 1) {
console.log('success');
console.log(result[0]); // by setting (result > 1) above, I can see that this line of code prints an array containing all available objects, not just the one selected.
ca_fdSetTextFieldValue(ca_fd.formId, 'email_addr', result[0].email_address.value);
}
else {
ca_fdSetTextFieldValue(ca_fd.formId, 'email_addr', 'Cannot find user details');
console.log(result);
}
},
onFailure : function(){
ca_fdSetTextFieldValue(ca_fd.formId, 'email_address', 'Failed');
},
}
The onSuccess functions runs, as the ReportQuery returns every possible userid. It jumps too the else{, part of the function.
However, if I set the (result > 1), it will try to set the email_addr field with the email address of the first user the Query returns, but the field in the form gets the value "undefined".
Any help is much appreciated!!
#ca_reportquery #catalogforms #select #variables #javascript