Using Epicor Environmental Variables To Pass Data In Between Forms
In Epicor, the typical way to launch a form and pass data into it is with ProcessCaller:
ProcessCaller.LaunchForm(oTrans, "OMMT1112", "MY-PART-NUMBER");
Where “OMMT1112” is a menu maintenance menu ID (in this case part maintenance) and you would replace “MY-PART-NUMBER” with the data you want to pass into the form (in this case a part number). But what happens when you want to pass data into a form that is not the key values? For example, we were working on a lot attributes customization where it was desired to pass in things like the receipt qty, UOM, and some UD values in order to calculate and auto-populate various fields. Well in that case you will want to employ Epicor environmental variables to pass the data. On the form that is the caller, you set environmental variables like so:
Environment.SetEnvironmentVariable("UOM", edvRcvDtl.dataView[edvRcvDtl.Row]["IUM"].ToString(), EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("SupplierUOM", edvRcvDtl.dataView[edvRcvDtl.Row]["PUM"].ToString(), EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("OurQty", edvRcvDtl.dataView[edvRcvDtl.Row]["OurQty"].ToString(), EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("VendorQty", edvRcvDtl.dataView[edvRcvDtl.Row]["VendorQty"].ToString(), EnvironmentVariableTarget.Process);
Here I have set 4 environmental variables for UOM, SupplierUOM, OurQty, and VendorQty. The first argument is the name for the variable and the second is the value cast to a string (here I have pulled from epiDataView values but this could just as easily be static strings). It is very important that you cast to a string here otherwise it will give you some grief. Then on the Epicor form that has been called you can retrieve these values like so:
var uom = Environment.GetEnvironmentVariable("UOM", EnvironmentVariableTarget.Process);
var vendorUom = Environment.GetEnvironmentVariable("VendorUOM", EnvironmentVariableTarget.Process);
var ourQty = Environment.GetEnvironmentVariable("OurQty", EnvironmentVariableTarget.Process);
var vendorQty = Environment.GetEnvironmentVariable("VendorQty", EnvironmentVariableTarget.Process);
var vendorNum = Environment.GetEnvironmentVariable("VendorNum", EnvironmentVariableTarget.Process);
Then from there you can use these values however you can imagine!. Hope this helps some of you out there!