I am receiving the following error in my code:
Condition for attribute 'sgfdhr_leavetype.new_employeeleavecalculation': expected argument(s) of type 'System.Guid' but received 'Microsoft.Xrm.Sdk.EntityReference'.
My code is below:
public int Getleavetype(Entity LeaveManagement, IOrganizationService _orgService, CodeActivityContext Acontext)
{
QueryExpression GetLeavedetails = new QueryExpression();
GetLeavedetails.EntityName = "sgfdhr_leavetype";
GetLeavedetails.ColumnSet = new ColumnSet("new_type");
GetLeavedetails.ColumnSet = new ColumnSet("new_availabledays");
GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, 1);
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal,LeaveManagement["new_leavedetails"]);
EntityCollection LeaveDetails = _orgService.RetrieveMultiple(GetLeavedetails);
return (int)LeaveDetails[0]["new_availabledays"];
}
I am recieving error on " EntityCollection LeaveDetails = _orgService.RetrieveMultiple(GetLeavedetails);" this line in above code.
Thanks,
The error is pretty clear you have this condition:
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, LeaveManagement["new_leavedetails"]);
The error is telling you that LeaveManagement["new_leavedetails"]
is an EntityReference
(lookup) and not a Guid
You can cast the field before and after put the Id
inside the condition:
EntityReference detailsRef = (EntityReference)LeaveManagement["new_leavedetails"];
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, detailsRef.Id);