1
0
-1

Below is the script to call DDS from zipcode field. How can I show a message like: "Enter a valid zipcode" at zipcode filed if my DDS returns no value for a entered zipcode?
var inputFieldRefs = [{
key: "ZIPCODE",
ref: "data.zipcode1"
}];

// The key "cities" is presumed to be the output parameter returned from the "Zipcode Lookup Service"
var outputFieldRefs = [{
key: "cities",
ref: "data.citydatafield1"
},{
key: "state",
ref: "data.state"
},{ key: "states",
ref: "data.statedatafield1" }];

var serviceName = "CityStateLookupServiceByZipcode";
var dataParams = Form.convertToFieldDataMap(inputFieldRefs, data);

// Character input must be length of valid zipcode before making request
if(data.zipcode1 && data.zipcode1.length === 5) {
proceed();
}

// Lookup promise
function proceed() {
// Make asynchronous call to DDS and when the response is received set the field data or log an error
DynamicData.call(serviceName, dataParams).then(function(response) {
// Update the form field data.cityDataField with the response data formatted for a Data-Drive Dropdown.
Form.setFieldDataFromResponse(outputFieldRefs, response, data);
}).catch(function(err) {
console.log("Error: ", err);
});
}

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hey Umakanta,

      The best way to achieve this would be to perform the DDS call in the Validate On Change rule of the zip code field.

      See also: The Best way to setup a field to have both sychronous and asynchronous validation

      If no values get returned then you can provide a validation message.

        CommentAdd your comment...