Epicor 10 - Changing the plant for the current session

2.2k Views Asked by At

We are starting to use Epicor 10 and we are wanting to leverage the DLLs/Services to talk to Epicor. That way we can add/update info from a custom app. So far things are going fine but we ran into an issue when we wanted to, lets say, add a job for a specific plant. It seems to always want to save to the plant the user last logged into via the client app.

So for example -- Lets say the user's last plant was plant "A". I want my custom app to log into Epicor (creating a session) and create a job for plant "B". I can add the job fine, but it will put it under plant "A" and not "B", even though I logged into plant "B" when I created the session.

We are calling SetPlant and passing in the right plant we want, but Epicor seems to always override what plant to save it as. Has anyone else run into this case? We are also having this issue with the Company. SetCompany doesnt seem to work at all.

More info: - We are using the net.tcp:///ERP/ICE/Lib/SessionMod.svc service. - We can login fine with Login() and get a SessionId back - Even calling GetValues() on the Session object says we are logged into plant "B" even though Epicor will still use plant "A".

The only work around we can come up with, which we do not want to do, is to have an app user by company and by plant so we can guarantee which company and plant the data gets saved to. This will work but it isnt ideal.

Anyone have any suggestions on how to get the system to take the new Company or Plant?

3

There are 3 best solutions below

0
On

The plantID can be updated in the session using the SetPlant() method. It must be called after the SetCompany():

sessionModImpl = NetTcp_Helper.ClassAttributHelper.CreateBusObj<SessionModImpl>(Guid.Empty, SessionModImpl.UriPath, Settings);

sessionId = sessionModImpl.Login();

sessionModImpl.SessionID = sessionId;

sessionModImpl.SetCompany(epicorCompanyID, out companyName, out plantID, out plantName, out workstationID, out workstationDescription, out employeeID,
                                        out countryGroupCode, out countryCode, out tenantID);

sessionModImpl.SetPlant(newSiteID, out plantName);
0
On

The first thing to understand is that a Server Session is not a single instance but rather a .NET Stack of Session Instances. The ‘CallContext.Current.Session’ variable is just a pointer to the top of the Stack. In most cases, there is just a single Session instance in the CallContext stack. But when you need to iterate over Companies to process something the Session Stack get pushed and popped around. That’s where ‘TemporarySessions’ comes in.

Read about it at: https://www.linkedin.com/pulse/snippet-epicor-change-companyplantuser-bpm-haso-keric/

0
On

As user463132 points out, you can wrap your service connection with the temporary session context:

using (CallContext.Current.TemporarySessionCreator.SetCompanyID("YourCompanyHere").SetPlantID("B").Create())
{
}

Haso Keric Article Reference

I'll also add that if you are using the UI adapters, you can simply grab the session from the oTrans object instance and set the properties here which governs how oTrans interacts with your data.

Ice.Core.Session s1 = (Ice.Core.Session)this.oTrans.Session;
s1.CompanyID = "YourCompanyHere";
s1.PlantID = "B";