Skip to main content
Answer

Join criteria not properly built in the query of a report

  • August 5, 2025
  • 4 replies
  • 83 views

Forum|alt.badge.img+1

Hi everybody,

We have added the new DAC TaxSpecialMentions to manage the notions of legal notices on ARInvoices.The link between the ARInvoice and the records of ths new DAC is done with TaxTaxTran where the new custom field SpectalMentionsID has been added.

Below the data model.


Objectives to be achieved

We have created a new report to display all the texts of the legal mentions for a given ARInvoice.

Below, the query we have created.


Issue:

When the reports runs, no data are found whereas they should be present. I catched the query and I realized that one of the join criteria is not properly built : the one dealing with [SpecialMentionsID] that is used to join ARTaxTran and TaxSpecialMentions.
We should have 
( [ARTaxTran_TaxTran].[SpecialMentionsID] = [TaxSpecialMentions].[SpecialMentionsID])
but we have

( NULL = [TaxSpecialMentions].[SpecialMentionsID])

Below the query with more details :

SELECT [ARInvoice_ARRegister].[DocType] AS [DocType], ..., [TaxSpecialMentions].[SpecialMentionsID] AS [SpecialMentionsID]
FROM (
[ARInvoice] [ARInvoice_ARInvoice]
INNER JOIN [ARRegister] [ARInvoice_ARRegister] ON ( [ARInvoice_ARRegister].[CompanyID] = 3) AND [ARInvoice_ARRegister].[DeletedDatabaseRecord] = 0 AND ( [ARInvoice_ARRegister].[BranchID] IS NULL OR ( [ARInvoice_ARRegister].[BranchID] IN ( 5, 2, 3, 4, 6, 7, 8))) AND [ARInvoice_ARInvoice].[DocType] = [ARInvoice_ARRegister].[DocType] AND [ARInvoice_ARInvoice].[RefNbr] = [ARInvoice_ARRegister].[RefNbr]
)
INNER JOIN [TaxTran] [ARTaxTran_TaxTran] ON ( [ARInvoice_ARRegister].[DocType] = [ARTaxTran_TaxTran].[TranType] AND [ARInvoice_ARRegister].[RefNbr] = [ARTaxTran_TaxTran].[RefNbr]) AND ( [ARTaxTran_TaxTran].[CompanyID] = 3) AND ( [ARTaxTran_TaxTran].[Module] = 'AR')
INNER JOIN [TaxSpecialMentions] [TaxSpecialMentions] ON ( [TaxSpecialMentions].[CompanyID] = 3) AND ( NULL = [TaxSpecialMentions].[SpecialMentionsID])
WHERE ( [ARInvoice_ARRegister].[DocType] = 'INV' AND [ARInvoice_ARRegister].[RefNbr] = '003175') AND ( [ARInvoice_ARInvoice].[CompanyID] = 3)
ORDER BY ((SELECT [TaxSpecialMentionsKvExt].[FieldName] as '@type', COALESCE(CONVERT(VARCHAR(30), ValueNumeric), CONVERT(VARCHAR(23), ValueDate, 121), ValueString, ValueText, N'') as '*' FROM [TaxSpecialMentionsKvExt] [TaxSpecialMentionsKvExt] WHERE ( [TaxSpecialMentionsKvExt].[CompanyID] = 3) AND [TaxSpecialMentionsKvExt].[RecordID] = [TaxSpecialMentions].[NoteID] FOR XML PATH('v')) ) OPTION(OPTIMIZE FOR UNKNOWN)/* TX.20.CG.01 */

How to fix that ? 

 

Best answer by ygagnaire12

We have found the fix ! In our first version, we had added the field SpecialMentionsID in a DAC extension of ARTaxTran. But the DAC ARTaxTran inherits (C# inheritage) from the DAC TaxTran. Acumatica needs us in this case to also create a DAC extension for TaxTran with our new custom field inside…

What we created first(and was not sufficient):
 

 public class ARTaxTranExt : PXCacheExtension<ARTaxTran>
{
public static bool IsActive() => true;

#region SpecialMentionsID
[PXDBInt]
[PXUIField(DisplayName = "Special Mention ID")]
public virtual int? SpecialMentionsID { get; set; }
public abstract class SpecialMentionsID : BqlInt.Field<SpecialMentionsID> { }
#endregion



}

 

What we added to fix the issue:

 public class TaxTranExt : PXCacheExtension<TaxTran>
{
public static bool IsActive() => true;


#region SpecialMentionsID
[PXDBInt]
[PXUIField(DisplayName = "Special Mention ID")]
public virtual int? SpecialMentionsID { get; set; }
public abstract class SpecialMentionsID : BqlInt.Field<SpecialMentionsID> { }
#endregion

}

 

4 replies

Forum|alt.badge.img+8
  • Captain II
  • August 5, 2025

@ygagnaire12 

 

As best practices, all custom fields in Acumatica should have the ‘Usr’ prefix.

You should be able to just use the field name in the join rather than TableName.FieldName

I have encountered issues when using that.


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • Answer
  • August 5, 2025

We have found the fix ! In our first version, we had added the field SpecialMentionsID in a DAC extension of ARTaxTran. But the DAC ARTaxTran inherits (C# inheritage) from the DAC TaxTran. Acumatica needs us in this case to also create a DAC extension for TaxTran with our new custom field inside…

What we created first(and was not sufficient):
 

 public class ARTaxTranExt : PXCacheExtension<ARTaxTran>
{
public static bool IsActive() => true;

#region SpecialMentionsID
[PXDBInt]
[PXUIField(DisplayName = "Special Mention ID")]
public virtual int? SpecialMentionsID { get; set; }
public abstract class SpecialMentionsID : BqlInt.Field<SpecialMentionsID> { }
#endregion



}

 

What we added to fix the issue:

 public class TaxTranExt : PXCacheExtension<TaxTran>
{
public static bool IsActive() => true;


#region SpecialMentionsID
[PXDBInt]
[PXUIField(DisplayName = "Special Mention ID")]
public virtual int? SpecialMentionsID { get; set; }
public abstract class SpecialMentionsID : BqlInt.Field<SpecialMentionsID> { }
#endregion

}

 


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • August 5, 2025

Thanks for your reply @aiwan . Like you, we realized during our tests that an error had been made in the way we named the field. We changed it, but this action did not change our problem.


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • August 5, 2025

Thank you for sharing your solution with the community ​@ygagnaire12!