Last active
November 26, 2017 03:35
-
-
Save smarenich/a3de809540e60375a719fc50fb0647a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DACExt : PXCacheExtension<DAC> | |
{ | |
#region UsrField | |
[PXDBInt] | |
[PXUIField(DisplayName = "My Field")] | |
[MultiCompanyList(new Object[] | |
{ | |
new Object[] { 2, //Company with ID 2 | |
new int[] { 1, 2, 3 }, //Values for Company 2 | |
new string[] { "1", "2", "3" } }, //Labels for Company 2 | |
new Object[] { 3, //Company with ID 3 | |
new int[] { 4, 5, 6 }, //Values for Company 3 | |
new string[] { "4", "5", "6" }} //Labels for Company 3 | |
})] | |
public virtual int? UsrField { get; set; } | |
public abstract class usrField : IBqlField { } | |
#endregion | |
} | |
//Attribute that can change values depend on company | |
public class MultiCompanyListAttribute : PXEventSubscriberAttribute, IPXFieldSelectingSubscriber | |
{ | |
protected Object[] Conditions; | |
public MultiCompanyListAttribute(Object[] conditions) | |
{ | |
Conditions = conditions; | |
} | |
public virtual void FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e) | |
{ | |
foreach (Object condition in Conditions) | |
{ | |
Object[] row = (Object[]) condition; | |
Int32 company = (Int32)row[0]; | |
if (PX.Data.Update.PXInstanceHelper.CurrentCompany == company) | |
{ | |
if(row[1] is String[]) | |
{ | |
e.ReturnState = PXStringState.CreateInstance(e.ReturnState, null, null, | |
_FieldName, false, 0, null, | |
(String[])row[1], | |
(String[])row[2], | |
null, null); | |
} | |
if (row[1] is Int32[]) | |
{ | |
e.ReturnState = PXIntState.CreateInstance(e.ReturnState, _FieldName, false, | |
0, null, null, | |
(Int32[])row[1], | |
(String[])row[2], | |
null, null); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment