Last active
April 4, 2023 13:51
-
-
Save pavanmanideep/c101d9d492cef0cbdbe30e23da532aa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ValidatePostalCode: function (executionContext) { | |
"use strict"; | |
var formContext = executionContext.getFormContext(); | |
var postalcode = formContext.getAttribute(Resident.Fields.address1_postalcode).getValue(); | |
var message = "Please enter a valid Postal code; Refer to Postal Code Mappings" | |
var uniqueId = "cnt_postalcodenotpresent"; | |
return new Promise(function (resolve, reject) { | |
Xrm.WebApi.retrieveMultipleRecords("new_postalcodes", "?$select=new_postalcode&$filter=hsg_postalcode eq '" + postalcode + "' ").then( | |
function success(result) { | |
var isNotFound = false; | |
if(result !== undefined) | |
isNotFound = result.entities.length === 0 ? true : false; | |
if (isNotFound) { | |
var errorMessage = "Postal Code Mapping is not present for the given postal code" | |
formContext.ui.setFormNotification(errorMessage, "ERROR", uniqueId); | |
} | |
else { | |
Resident.isValidationNeeded = false; | |
formContext.ui.clearFormNotification(uniqueId); | |
formContext.data.entity.save(); | |
} | |
// return true or false | |
resolve(isNotFound); | |
}, | |
function (error) { | |
reject(error.message); | |
//console.log(error.message); | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment