如果来自 Xrm.WebApi.online.retrieveRecord 函数内部,如何将 false 返回到主函数?
我创建了一个 javascript 函数来在另一个实体中进行一些验证。验证正在工作,但我试图从内部函数返回 false 到主函数,我是 Dynamics 365 框架和 javascript
代码中的新手:
function SubmitAction(executionContext) {
var formContext = executionContext.getFormContext();
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var languageCode = userSettings.languageId;
var isAirportValis = ValidateAirportCountry(executionContext);
var IsConfidential=formContext.getAttribute("alfa_confidentialguest").getValue();
var a = true;
//Edit by Abdallah To get the package Type so we can get the package type
var lookupItem = formContext.getAttribute("alfa_member").getValue()[0].id;
var theTotalMembersTravling = formContext.getAttribute("alfa_numberofdependent").getValue();
var remainFlightCredit;
debugger;
Xrm.WebApi.online.retrieveRecord("contact",lookupItem, "?$select=new_remainstravelcredit").then(
function employessPackage(result) {
var new_remainstravelcredit = result["new_remainstravelcredit"];
if(new_remainstravelcredit !== null){
if(new_remainstravelcredit > 0)
{
remainFlightCredit = new_remainstravelcredit;
console.log(remainFlightCredit+" This not inside any if condition");
var newRemain = (parseInt(remainFlightCredit)) - (parseInt(theTotalMembersTravling));
console.log(newRemain+ " This in the remain if condition");
var entity = {};
entity.new_remainstravelcredit = newRemain.toString();
Xrm.WebApi.online.updateRecord("contact",lookupItem, entity).then(
function success(result) {
var updatedEntityId = result.id;
},
function(error) {
Xrm.Utility.alertDialog(error.message +" This error is occuring from retriveing the altanfeethi emplyees packgae");
}
);
} if(new_remainstravelcredit <= 0)
{
Xrm.Utility.alertDialog("You have exceeds the travel credit");
return false;
// throw Xrm.Utility.alertDialog("You have exceeds the travel credit");
}
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
if (!isAirportValis) {
return false;
}
//var isAttachemntValid = ValidateAttachments(formContext);
//if (!isAttachemntValid) {
// return false;
//}
var hasTravellers = ValidateTravellers(formContext)
if (!hasTravellers && !IsConfidential) {
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var languageCode = userSettings.languageId;
if (languageCode == "1033") {
alert(Messages.FlightMemberCountValidation1033);
}
else {
alert(Messages.FlightMemberCountValidation1025);
}
return false;
}
var isGuestValid = isValidGuest(formContext);
var isPaymentValid = false;
var guestPaymentType = formContext.getAttribute('alfa_guestpaymenttype').getValue();
var addedGuestServices = formContext.getControl('guestservices').getGrid().getTotalRecordCount();
if (!isGuestValid) {
var membershipType = GetMembershipType();
if (membershipType != MembershipTypeEnum.Corportate) // Individual
{
formContext.getControl('alfa_guestpaymenttype').setVisible(true);
formContext.getAttribute('alfa_guestpaymenttype').setRequiredLevel('required');
if (!guestPaymentType) {
if (languageCode == "1033")
alert(Messages.IndividualGuestSub1033);
else alert(Messages.IndividualGuestSub1025);
formContext.getControl('alfa_guestpaymenttype').setFocus();
return false;
}
else if (guestPaymentType == GuestPaymentTypeEnum.BuyPackage) {
if (addedGuestServices == 0) {
if (languageCode == "1033")
alert(Messages.AddGuestService1033);
else alert(Messages.AddGuestService1025);
formContext.getControl('guestservices').setFocus();
return false;
}
else isPaymentValid = true;
}
else if (guestPaymentType == GuestPaymentTypeEnum.PayForAdded)
isPaymentValid = true;
}
else // Corp
{
formContext.getControl('alfa_guestpaymenttype').setVisible(false);
//var addedGuestServices = formContext.getControl('guestservices').getGrid().getTotalRecordCount();
// if (addedGuestServices == 0) {
if (languageCode == "1033")
alert(Messages.AddGuestService1033);
else alert(Messages.AddGuestService1025);
formContext.getControl('guestservices').setFocus();
return false;
// }
//else isPaymentValid = true;
}
if (isPaymentValid) {
formContext.getAttribute('alfa_requirepayment').setValue(true);
formContext.getAttribute('alfa_issubmitted').setValue(true);
formContext.data.save();
}
}
else {
formContext.getAttribute('alfa_requirepayment').setValue(addedGuestServices > 0);
formContext.getControl('alfa_guestpaymenttype').setVisible(false);
formContext.getAttribute('alfa_guestpaymenttype').setRequiredLevel('none');
formContext.getAttribute('alfa_issubmitted').setValue(true);
formContext.data.save();
}
}
在 if 条件检查“if(new_remainstravelcredit <= 0)”的行中 我想从主函数“SubmitAction”返回 false,但它不起作用,因为当它进入 if 条件 if(new_remainstravelcredit <= 0) 时,它会恢复主函数实现。有关如何强制返回 false 并从内部函数 emploessPackage 退出 SumbitAction 函数的任何建议
I have created a javascript function to do some validation in another entity. The validation is working but I am trying to return false to the main function from inside function, I am new in dynamics 365 framework and in javascript
the code:
function SubmitAction(executionContext) {
var formContext = executionContext.getFormContext();
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var languageCode = userSettings.languageId;
var isAirportValis = ValidateAirportCountry(executionContext);
var IsConfidential=formContext.getAttribute("alfa_confidentialguest").getValue();
var a = true;
//Edit by Abdallah To get the package Type so we can get the package type
var lookupItem = formContext.getAttribute("alfa_member").getValue()[0].id;
var theTotalMembersTravling = formContext.getAttribute("alfa_numberofdependent").getValue();
var remainFlightCredit;
debugger;
Xrm.WebApi.online.retrieveRecord("contact",lookupItem, "?$select=new_remainstravelcredit").then(
function employessPackage(result) {
var new_remainstravelcredit = result["new_remainstravelcredit"];
if(new_remainstravelcredit !== null){
if(new_remainstravelcredit > 0)
{
remainFlightCredit = new_remainstravelcredit;
console.log(remainFlightCredit+" This not inside any if condition");
var newRemain = (parseInt(remainFlightCredit)) - (parseInt(theTotalMembersTravling));
console.log(newRemain+ " This in the remain if condition");
var entity = {};
entity.new_remainstravelcredit = newRemain.toString();
Xrm.WebApi.online.updateRecord("contact",lookupItem, entity).then(
function success(result) {
var updatedEntityId = result.id;
},
function(error) {
Xrm.Utility.alertDialog(error.message +" This error is occuring from retriveing the altanfeethi emplyees packgae");
}
);
} if(new_remainstravelcredit <= 0)
{
Xrm.Utility.alertDialog("You have exceeds the travel credit");
return false;
// throw Xrm.Utility.alertDialog("You have exceeds the travel credit");
}
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
if (!isAirportValis) {
return false;
}
//var isAttachemntValid = ValidateAttachments(formContext);
//if (!isAttachemntValid) {
// return false;
//}
var hasTravellers = ValidateTravellers(formContext)
if (!hasTravellers && !IsConfidential) {
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var languageCode = userSettings.languageId;
if (languageCode == "1033") {
alert(Messages.FlightMemberCountValidation1033);
}
else {
alert(Messages.FlightMemberCountValidation1025);
}
return false;
}
var isGuestValid = isValidGuest(formContext);
var isPaymentValid = false;
var guestPaymentType = formContext.getAttribute('alfa_guestpaymenttype').getValue();
var addedGuestServices = formContext.getControl('guestservices').getGrid().getTotalRecordCount();
if (!isGuestValid) {
var membershipType = GetMembershipType();
if (membershipType != MembershipTypeEnum.Corportate) // Individual
{
formContext.getControl('alfa_guestpaymenttype').setVisible(true);
formContext.getAttribute('alfa_guestpaymenttype').setRequiredLevel('required');
if (!guestPaymentType) {
if (languageCode == "1033")
alert(Messages.IndividualGuestSub1033);
else alert(Messages.IndividualGuestSub1025);
formContext.getControl('alfa_guestpaymenttype').setFocus();
return false;
}
else if (guestPaymentType == GuestPaymentTypeEnum.BuyPackage) {
if (addedGuestServices == 0) {
if (languageCode == "1033")
alert(Messages.AddGuestService1033);
else alert(Messages.AddGuestService1025);
formContext.getControl('guestservices').setFocus();
return false;
}
else isPaymentValid = true;
}
else if (guestPaymentType == GuestPaymentTypeEnum.PayForAdded)
isPaymentValid = true;
}
else // Corp
{
formContext.getControl('alfa_guestpaymenttype').setVisible(false);
//var addedGuestServices = formContext.getControl('guestservices').getGrid().getTotalRecordCount();
// if (addedGuestServices == 0) {
if (languageCode == "1033")
alert(Messages.AddGuestService1033);
else alert(Messages.AddGuestService1025);
formContext.getControl('guestservices').setFocus();
return false;
// }
//else isPaymentValid = true;
}
if (isPaymentValid) {
formContext.getAttribute('alfa_requirepayment').setValue(true);
formContext.getAttribute('alfa_issubmitted').setValue(true);
formContext.data.save();
}
}
else {
formContext.getAttribute('alfa_requirepayment').setValue(addedGuestServices > 0);
formContext.getControl('alfa_guestpaymenttype').setVisible(false);
formContext.getAttribute('alfa_guestpaymenttype').setRequiredLevel('none');
formContext.getAttribute('alfa_issubmitted').setValue(true);
formContext.data.save();
}
}
In the line where the if condition checking "if(new_remainstravelcredit <= 0)"
I want to return false from the main function "SubmitAction" but it does not work as when it goes inside the if condition if(new_remainstravelcredit <= 0) it then resume with the main function implementation. Any suggestions on how can I enforce to return false and exit the SumbitAction function from the inner function emploessPackage
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)