In project1, I have some extension fields in GLTran and project 2, I have some extension field in GLTran too. In project 2, I want to access the extension field in GLTran of project 1. How to access that ?
Solved
I have two projects that extend GLTran
Best answer by vardan22
You can do that via one of the next ways:
1. By referencing Project1.dll in the Project2 and use the Project1 objects as usual referenced .dll objects.
2. If you donβt want to create reference between projects you can get field value via hardcoded field name and cache:
For example:
In the project1 you have:
public sealed class P1GLTranExt : PXCacheExtension<GLTran>
{
public static bool IsActive() => true;
#region UsrProject1TestField
[PXDBString(30, IsUnicode = true)]
[PXUIField(DisplayName = "Project1 Test Field")]
public string UsrProject1TestField { get; set; }
public abstract class usrProject1TestField : BqlType<IBqlString, string>.Field<usrProject1TestField> { }
#endregion
}
In the project2 you have:
public sealed class P2GLTranExt : PXCacheExtension<GLTran>
{
public static bool IsActive() => true;
#region UsrProject1TestField
[PXDBString(30, IsUnicode = true)]
[PXUIField(DisplayName = "Project2 Test Field")]
public string UsrProject2TestField { get; set; }
public abstract class usrProject2TestField : BqlType<IBqlString, string>.Field<usrProject2TestField> { }
#endregion
}
And In the project 2 you can do the following
public class JournalEntryExt : PXGraphExtension<JournalEntry>
{
public static bool IsActive() => true;
#region example 1
public override void Initialize()
{
base.Initialize();
base.Base.FieldUpdated.AddHandler("ViewName_Where_Field_Added", "FieldName_UsrProject1TestField", new PXFieldUpdated(FieldUpdated));
}
protected virtual void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
if (e.Row is GLTran row)
{
string project1FieldValue = (string)sender.GetValue(e.Row, "UsrProject1TestField");
if (!string.IsNullOrEmpty(project1FieldValue))
{
//do something
}
}
}
#endregion
#region example 2
public virtual void _(Events.FieldUpdated<GLTran, P2GLTranExt.usrProject2TestField> e)
{
if (e.Row is GLTran)
{
string project1FieldValue = (string)e.Cache.GetValue(e.Row, "UsrProject1TestField");
if (!string.IsNullOrEmpty(project1FieldValue))
{
//do something
}
}
}
#endregion
}
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.