How to add Data Method to Entity as a field

I need to add the ARPTaskId_Wbs field (from an ISV) to a copied version of the ExpenseJournalLineEntity data entity.

The field is not stored in the database but is calculated in the form using the following method in the ISV extension:

[ExtensionOf(tableStr(LedgerJournalTrans_Project))]
public final class LedgerJournalTrans_Project_ARP_Extension
{
    /// display/edit
    public static edit ARPTaskId_Wbs ARPTaskWBSId(LedgerJournalTrans_Project _this, boolean _set, ARPTaskId_Wbs _wbs)
    {
        [_wbs, _this.ActivityNumber] = ARPTasktools::TaskWBSId_edit(_this.projId, '', _set, _wbs, _this.ActivityNumber);
        return _wbs;
    }
}

Since LedgerJournalTrans_Project is already part of my entity, I am trying to create a computed field to retrieve ARPTaskId_Wbs dynamically.

Here’s what I have so far:

public static str computeSID(ProjActivityNumber activityNumber)
{
    LedgerJournalTrans_Project ledgerJournalTransProject;

    // Retrieve the record based on ActivityNumber
    select firstonly ledgerJournalTransProject
        where ledgerJournalTransProject.ActivityNumber == activityNumber;

    // Ensure a record is found before calling the method
    if (ledgerJournalTransProject)
    {
        return LedgerJournalTrans_Project_ARP_Extension::ARPTaskWBSId(
            ledgerJournalTransProject, 
            false,  // Boolean flag
            ''      // Placeholder for ARPTaskId_Wbs
        );
    }

    return ""; // Return empty string if no match is found
}

So the issues I’m seeing:

  • The computed field is not retrieving any data, and I am unsure if I am calling the method correctly.
  • The ARPTaskWBSId method is defined in an extension but does not seem to work inside the computed column.
  • Should I be calling this differently, or is there an issue with using a computed column in this case?

Has anyone successfully retrieved an ISV-calculated field in a computed column inside a copied data entity?
Would it be better to store this value instead of computing it dynamically?

Any help would be appreciated!

Your code is fundamentally wrong. The purpose of a computed column is to generate a piece of SQL code that is inserted to the view definition. Your code does nothing like that.

If you want to call X++ code obtaining the value, use a virtual field (instead of a computed column) and call the code and assign the field value in postLoad().

If you want to use a computed column, you’ll need to analyze what ARPTasktools::TaskWBSId_edit() does, rewrite it to T-SQL (if it’s possible at all) and then write X++ code generating this T-SQL code.