I have a Function that calls our Dayforce API and then terminates an employee if they are termed in our Dayforce system. I am getting the below error. the main issue is Cannot perform runtime binding on a null reference. not sure where in the code I have a null value that is causing the issue.
Any help is appreciated.
Exception executing library 'DayForce' function 'termEmplolyee':
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at EFx.DayForce.Implementation.termEmplolyeeImpl.Run()
at Epicor.Functions.FunctionBase`3.Run(TInput input) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Internal\Lib\Epicor.Functions.Core\FunctionBase.cs:line 75
at EFx.DayForce.Implementation.termEmplolyeeImpl.AdapterRun(Object[] input)
at Ice.Internal.Task.ScheduledFunction.ExecuteFunction.RunFunction(IFunctionAdapter functionAdapter, Object[] parameters) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Internal\Task\ScheduledFunction\ExecuteFunction.cs:line 128
at Ice.Internal.Task.ScheduledFunction.ExecuteFunction.RunProcess(Int64 instanceTaskNum, String outputFileName) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Internal\Task\ScheduledFunction\ExecuteFunction.cs:line 57
Program Ice.Services.Lib.RunTask raised an unexpected exception with the following message: RunTask:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at EFx.DayForce.Implementation.termEmplolyeeImpl.Run()
at Epicor.Functions.FunctionBase`3.Run(TInput input) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Internal\Lib\Epicor.Functions.Core\FunctionBase.cs:line 75
at EFx.DayForce.Implementation.termEmplolyeeImpl.AdapterRun(Object[] input)
at Ice.Internal.Task.ScheduledFunction.ExecuteFunction.RunFunction(IFunctionAdapter functionAdapter, Object[] parameters) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Internal\Task\ScheduledFunction\ExecuteFunction.cs:line 128
at Ice.Internal.Task.ScheduledFunction.ExecuteFunction.RunProcess(Int64 instanceTaskNum, String outputFileName) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Internal\Task\ScheduledFunction\ExecuteFunction.cs:line 71
at Ice.Core.TaskBase`1.StartProcess(Int64 instanceTaskNum, String outputFileName) in C:\_releases\ICE\ICE3.2.700.33\Source\Server\Internal\Lib\TaskLib\TaskBase\TaskBase.cs:line 83
at Ice.Hosting.TaskCaller.InnerExecuteTask(IceDataContext newContext) in C:\_releases\ICE\ICE3.2.700.33\Source\Framework\Epicor.Ice\Hosting\TaskCaller\TaskCaller.cs:line 117
at Ice.Hosting.TaskCaller.ExecuteTask() in C:\_releases\ICE\ICE3.2.700.33\Source\Framework\Epicor.Ice\Hosting\TaskCaller\TaskCaller.cs:line 59
at Ice.Lib.RunTask.BpmFriendlyTaskLauncher.Run(String sessionIdPrefix, IceContext db, Action taskRunner) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Services\Lib\RunTask\BpmFriendlyTaskLauncher.cs:line 63
at Ice.Services.Lib.RunTaskSvc.InnerRunTask(Int64 ipTaskNum, Boolean suppressTransaction) in C:\_Releases\ICE\ICE3.2.700.0\Source\Server\Services\Lib\RunTask\RunTask.cs:line 454
var client = "ServerCall";
var myDate = BpmFunc.Today();
var termOneDate = myDate.ToString("yyyy-MM-dd");
var termTwoDate = BpmFunc.Today().AddDays(-1).ToString("yyyy-MM-dd");
var restClient = new RestClient(client);
var request = new RestRequest($"/Api/zacs/V1/Employees?filterTerminationStartDate=2024-9-26&filterTerminationEndDate=2024-9-28", Method.GET);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "••••••");
request.AddHeader("Cookie", "_Classified");
request.AddParameter("Grant_type", "password");
request.AddParameter("CompanyId", "Classified");
request.AddParameter("Username", "Classified");
request.AddParameter("Password", "Classified");
request.AddParameter("Client_Id", "Dayforce.HCMAnywhere.Client");
var response = restClient.Execute(request);
this.output = response.Content.ToString();
dynamic json = JsonConvert.DeserializeObject<dynamic>(response.Content);
//Count to see how big the object is for our for loop
int count = json["Data"].Count;
this.output2 = count;
for(int i = 0; i < count; i++)
{
var empXrefCode = json.Data[i].XRefCode.ToString();
string newEmpId = empXrefCode.ToString();
var employee = Db.EmpBasic.Where(x => x.Company == "TIMCO" && x.EmpID == newEmpId).FirstOrDefault();
if(employee == null)
{
return;
}
if(employee.EmpStatus == "A")
{
employee.EmpStatus = "I";
}
if(employee.TermStatus_c == false)
{
employee.TermStatus_c = true;
}
employee.TermDate_c = BpmFunc.Today();
Db.SaveChanges();
}