Change company inside Epicor Function

Hi,

I am creating an epicor function which will grab data from one company to the current company.

In order to do this, I would like to change company - a temporary session.

I have been able to do this using BPM - which can be done as shown below:-

using(CallContext.Current.TemporarySessionCreator.SetCompanyID("NAME_OF_COMPANY").Create())
{
    // code in here.
}

What is the equiverland to achieve the same thing inside Epicor functions?

Cheers
Edit: Formatted the code.

Try the below code.

string c1="",c2="",c3="",c4 ="" ,c5="",c6="" ,c7="",c8="" ,c9="";
bool c10=true;
Ice.Contracts.SessionModSvcContract SessionCompany = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.SessionModSvcContract>(Db);

SessionCompany.SetCompany(dr.Company1.ToString(),out c1,out c2,out c3 ,out c4,out c5,out c6 ,out c7,out c8 ,out c9,out c10);
Db.Validate();
Db.SaveChanges();
SessionCompany.UpdateSeedData();

1 Like

Hi fakhruddin,

Thanks for this – I will have a look shortly. However, I don’t think Db is supported in Epicor Functions (it is in BPM) so I am not sure if this will work.

I will update shortly… thanks.

We can enable DB access in Epicor Functions.

It looks like you have more options. Maybe this is later version of epicor.

I am on 10.2.500.35

If I had access to Db then it would have been a quick/easy win… but I do not have it in (our) Epicor Functions.
This is why I am looking at the BPM Temporary Session alternative… hoping one would exist.

If I have Db, then I would have simply done something like:-

var p = Db.Parts.FirstOrDefault(p => p.Company == "COMPANY_I_WANT_DATA" and p.PartNum == PartNumVar);

// etc ... get what I want from p to currentCompany