The difference between Session.CompanyID and callContextClient.CurrentCompany

I want to confirm the difference of 2 local variables Session.CompanyID and callContextClient.CurrentCompany
Session.CompanyID: assigned only at login and stored for the duration of a session
callContextClient.CurrentCompany: get the correct information of the company you are standing for in case you use it for many companies when you log in at company A and you switch to company B
In bpm and customization, you should use the CurrentCompany variable instead of the CompanyID variable, also depending on the case you want to determine which company you used to initially login at, then use CompanyID

in customization:

string companyCurrent = string.Empty;
	EpiDataView edvClientData = (EpiDataView)(oTrans.EpiDataViews["CallContextClientData"]);
	companyCurrent = edvClientData.dataView[edvClientData.Row]["CurrentCompany"].ToString();
string companyCurrent = string.Empty;
		EpiDataView edvClientData = (EpiDataView)(oTrans.EpiDataViews["CallContextClientData"]);
		companyCurrent = edvClientData.dataView[edvClientData.Row]["CurrentCompany"].ToString();
		session = (Session)this.oTrans.Session;
		MessageBox.Show("callContextClient.CurrentCompany :" + companyCurrent +"\n Session.CompanyID: " + session.CompanyID.ToString());

image
I checked again, maybe when the change company system doesn’t recognize the change, there will be a difference between the two variables
depending on where you initiate the session in the desktop
image
image

in BPM:

//kiểm tra dữ liệu trước khi lưu để có thể làm được báo cáo dự toán Forecast của khách hàng cho sale
foreach(var i in ttForecast.Where(w=>w.Company==callContextClient.CurrentCompany && (w.RowMod=="A" || w.RowMod=="U")).ToList())
{        
    if (String.IsNullOrEmpty(i.ShortChar01))
    {
         throw new Ice.BLException("DMS-DataForecast-DMS_CheckForecastPeriod: This Forecast does not have PeriodType!\nPlease select PeriodType!");
    }
    if (String.IsNullOrEmpty(i.ShortChar06))//Year Issue
    {
         throw new Ice.BLException("DMS-DataForecast-DMS_CheckForecastPeriod: This Forecast does not have Year Issue!\nPlease select Year Issue!");
    }
    else if (i.ShortChar01.ToUpper() =="WEEK" && String.IsNullOrEmpty(i.ShortChar02))
      {
           throw new Ice.BLException("DMS-DataForecast-DMS_CheckForecastPeriod: This Forecast does not have Week!\nPlease select Week!");
      }
    else if (i.ShortChar01.ToUpper() =="MONTH" && String.IsNullOrEmpty(i.ShortChar03))
      {
          throw new Ice.BLException("DMS-DataForecast-DMS_CheckForecastPeriod: This Forecast does not have Month!\nPlease select Month!");
      }
}


:thinking: :thinking:
Thanks you! Have a nice day! :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: :thinking: :thinking:

1 Like

I never thought about the difference between the two, but this feels like something I ought to understand. So I’m also hoping someone can clarify.

I somewhat know the answer. But I dont know the history, so maybe @Rich or @timshuwy can elaborate and get a more in-depth official answer with some history.

Could not replicate this and it seems fine to me.

image

Scenario 1)
Company C001, opened ABC Entry and the BPM fired.

image

Closed ABC Entry, switched to Company C002, opened ABC Entry and it fired with the C002 data in both.

image

Scenario 2)
Company C001, opened ABC Entry and the BPM fired with the results from the first step.
Then, I left ABC Entry open and switched to company C002 and the BPM fired with this, which is what I would expect.


Same results when tested in the UI.

1 Like

That doesn’t sound correct… i think that these should always act the same, and as @hmwillett found, they were.

1 Like

I always use Session.CompanyID because there are cases where callContext is and was Blank. I did use callContext more during the Service Connect days. But now its all about Session.CompanyID for me.

2 Likes

Is set by the client (Classic, Kinetic UX, REST etc) Session is stored and updated on the server side, when you change Companies (via SessionMod in classic) or by CallContext in REST it changes it on the Session side too. I would be remiss to use CallContext for much of anything since it can be manipulated from the clientside pretty easily.

1 Like

shudder You had to bring that up?! :upside_down_face:

One such case is if you use a schedule to trigger a BPM which I have done a couple times to run little utilities. Guess how many hours I spent trying to figure out why my BPM would work “sometimes” but not others?

External APIs are not required to provide callContext. I can Login and make an API call without callContext just fine or atleast I could… I had UpdateExt breaking alot, once I switched to Session.CompanyID never had an issue and we have 30+ Multi-Companies.

1 Like

@thanvanhai To throw out a potential reason you saw this…

I have heard that the epiDataView for callContext can be bad at updating. Do you only see the different companies show up in a customization?

CallContext is maintained by the Epicor Clients and is optional but can be configured when using REST. The CallContext Company value is set from Session as the Epicor UI is created. After that, it is not adjusted and should match the Session Company value (unless Company on Session is manipulate with Custom Code). There is one exception to this - a Dashboard with a Multi-Company BAQ. When you click into a row on the Multi-Company BAQ, I believe the EpiMagic adjusts the Session Company to match the Company on the BAQ Row so “Open With” will pass the proper context.

The CallContext Data is generally not manipulated by Epicor but BPMData is used for passing the Answers to BPM InfoPrompts and there is an Error Table that passes UBAQ Update error information from the Server to the Client.

5 Likes

Session.CompanyID and I debug the code did not change because at that time I logged in at company 01 then I changed to company 09 to do it and saw that Session.CompanyID was still 01 I tried Clear Client Cache but it was still 01
so I tried switching to callContextClient.CurrentCompany, it hides the tab I want and I also debug or use MessageBox.Show to check
I think there is a case where Session.CompanyID has not changed when changing company

Thank you! Have a nice day! :thinking: :thinking: :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: