Hi,
I am getting the "Entity Reference cannot have Id and Key Attributes empty." error when I include
if (accountingPeriodGuid != Guid.Empty)
{
objLoanDetail[EmpLoanDetail.AccountingPeriod] = new EntityReference(EnityUtility.AccountingPeriod, accountingPeriodGuid);
}
above mentioned logic in my code.Basically I am checking if EMI month is out of accounting period end month range then the accounting period lookup should remain empty..When I remove the above code from my code it works fine.Anyone know the reason?. My code is as given below:
if (EMIMonth > AccPeriodEndMonth && currentYear == AccPeriodEndYear) { accountingPeriodGuid = Guid.Empty; }
Entity objLoanDetail = new Entity(EnityUtility.EmployeeLoanDetail);
objLoanDetail[EmpLoanDetail.LoanReqId] = new EntityReference(EnityUtility.AdvanceLoanRequestEntity, Guid.Parse("3EDAAABF-BE9E-E711-816E-E0071B69C9D1"));
objLoanDetail[EmpLoanDetail.PrincipalAmount] = new Money(pAmount);
objLoanDetail[EmpLoanDetail.EmiAmount] = new Money(emi);
objLoanDetail[EmpLoanDetail.EmiMonth] = new OptionSetValue(EMIMonth);
objLoanDetail[EmpLoanDetail.Year] = new EntityReference(EnityUtility.YearEntity, yearGuid);
if (accountingPeriodGuid != Guid.Empty)
{
objLoanDetail[EmpLoanDetail.AccountingPeriod] = new EntityReference(EnityUtility.AccountingPeriod, accountingPeriodGuid);
}
objLoanDetail[EmpLoanDetail.EmiStatus] = new OptionSetValue(1);
service.Create(objLoanDetail);
*This post is locked for comments
If this is registered as a custom action called in a workflow, it is likely that you have specified an output entityreference arguement as required, but your workflow is returning null. Check to see if any of your action output variables are required. If so, set them to optional, save, publish, update plugins and try it then. This fixed the error for me. The problem wasn't the code, it was the action expecting something to be returned.
Hi,
where do you define that accountingPeriodGuid variable? Is the error happening every time? Is it a single-threaded application? Do you know if the error is coming from the "create" call or from the new EntityReference call?
Hi,
As the error message says, you need to validate the value of EnityUtility.AccountingPeriod & accountingPeriodGuid. They both have to contain the correct value.
To confirm if this is the cause, you can hardcode these values and check. It is more likely that you have blank for EnityUtility.AccountingPeriod.
Hope it helps.
Hi,
in your if statement you also need to check if accountPeriod != null
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156