Skip to main content

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 ?

@kevinheng21  Have you built both projects on DLL? 

If yes, you can use the DLL reference.

If not and created on the customization project (App_Runtime) then you can simply add those fields in the Project2 in the GLTran extension and use them (but no need to add database script for those fields in the Project2)


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
rPXDBString(30, IsUnicode = true)]
rPXUIField(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