hi,
I've added the customcontrol AutoComplete to 2 formfields (address1_postalcode, address1_city) and configured it with a custom entity where I have many addresses stored.
When I type in an postalcode a list of all matching postalcodes is show ---> thats fine.
But when I add an onchange event (to set the postalcode or the city - depending on the changed field) I get no error and It simply will not set the field-value.
this is my code:
function initAutocomplete(context, postalcodeFieldName, cityFieldName) {
var formContext = context.getFormContext();
var fields = [postalcodeFieldName, cityFieldName];
for (var i = 0; i < fields.length; i++) {
formContext.getAttribute(fields[i]).addOnChange(function (executionContext) {
autocompleteCalled(executionContext.getFormContext(), countyFieldName, postalcodeFieldName, cityFieldName, executionContext.getEventSource());
});
}
}
function autocompleteCalled(formContext, postalcodeFieldName, cityFieldName, sourceField) {
//"address1_postalcode", "address1_city", "address1_stateorprovince"
var sourceName = sourceField.getName();
var sourceValue = sourceField.getValue();
if (sourceValue == null)
return;
var column = "";
switch (sourceName) {
case postalcodeFieldName:
column = "bsw_postalcode";
break;
case cityFieldName:
column = "bsw_city";
break;
default:
return;
}
var filter = $bsw.string.format("{0} eq '{1}'", column, sourceValue);
var first = $bsw.remote.retrieveFirst("bsw_geodata", "bsw_postalcode,bsw_city", filter);
if (!first)
return;
console.log(postalcodeFieldName + "=" + first["bsw_postalcode"]);
console.log(cityFieldName + "=" + first["bsw_city"]);
formContext.getAttribute(countyFieldName).setValue(first["bsw_stateorprovince"]);
formContext.getAttribute(postalcodeFieldName).setValue(first["bsw_postalcode"]);
}
i also tried to use Xrm.Page directly in the console of chrome to set any text without success..
any ideas?
*This post is locked for comments
I have the same question (0)