Skip to main content
Answer

I have two projects that extend GLTran

  • September 25, 2023
  • 2 replies
  • 56 views

Forum|alt.badge.img

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 ?

Best answer by VardanV

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
}

 

2 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • September 25, 2023

@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)


VardanV
Jr Varsity III
Forum|alt.badge.img+1
  • Jr Varsity III
  • Answer
  • September 25, 2023

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
}