如何防止在 Dynamics 365 中保存表单
How can I prevent a form from saving in Dynamics 365
如果输入的“dni”值已经被另一个“人”注册,我想阻止表单保存,我试图在它的 onSave 事件中阻止表单保存,然后如果我的条件匹配,我然后保存表格。所以我做了以下代码:
function saveDni(executionContext) {
try {
const formContext = executionContext.getFormContext();
const currentDni = formContext.getAttribute("cr6ff_dni").getValue();
executionContext.getEventArgs().preventDefault();
var fetchXml = [
"<fetch top='1'>",
" <entity name= 'cr6ff_person'>",
" <filter>",
" <condition attribute='cr6ff_dni' operator='eq' value='", currentDni, "'/>",
" </filter>",
" </entity>",
"</fetch>",
].join("");
fetchXml = "?fetchXml=" + encodeURIComponent(fetchXml);
Xrm.WebApi.retrieveMultipleRecords("cr6ff_person", fetchXml).then(
(result) => {
if (result.entities.length == 0) {
formContext.data.entity.save();
}
}
)
}
catch(error) {
console.log("An error has occurred while validating the user's data.");
}
问题是,当 save() 方法触发时,它还会再次触发此函数,所以我陷入了循环。关于如何解决这个问题的任何想法?
如果输入的“dni”值已经被另一个“人”注册,我想阻止表单保存,我试图在它的 onSave 事件中阻止表单保存,然后如果我的条件匹配,我然后保存表格。所以我做了以下代码:
function saveDni(executionContext) {
try {
const formContext = executionContext.getFormContext();
const currentDni = formContext.getAttribute("cr6ff_dni").getValue();
executionContext.getEventArgs().preventDefault();
var fetchXml = [
"<fetch top='1'>",
" <entity name= 'cr6ff_person'>",
" <filter>",
" <condition attribute='cr6ff_dni' operator='eq' value='", currentDni, "'/>",
" </filter>",
" </entity>",
"</fetch>",
].join("");
fetchXml = "?fetchXml=" + encodeURIComponent(fetchXml);
Xrm.WebApi.retrieveMultipleRecords("cr6ff_person", fetchXml).then(
(result) => {
if (result.entities.length == 0) {
formContext.data.entity.save();
}
}
)
}
catch(error) {
console.log("An error has occurred while validating the user's data.");
}
问题是,当 save() 方法触发时,它还会再次触发此函数,所以我陷入了循环。关于如何解决这个问题的任何想法?