web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Temp table present in form datasource display method is not getting filled with data.

(1) ShareShare
ReportReport
Posted on by 211
Hi Friends ,

I am having an issue in the display method present in form datasource which is of temp table.The temp table is not populating the data in the display method inspite of inserting the records in the init method of the temp table datasource.I have debugged the code in the init method and the data is inserted in the temp table however in the display method the _record is empty and it is not showing up.Need your inputs.

Below is the code present in init method , display method and execute query method of the temp table datasource.Temp table is named PMIPProjectDateTemp.This temp table is joined with the datasource PMIPProjectsSorting(Regular table) with an inner join as shown in the below screenshot.


 
[DataSource]
class PMIPProjectDateTemp
{
    /// <summary>
    /// Gets the project name to display in the hierarchical grid
    /// ProjId:Name
    /// </summary>
    /// <param name = "_record">PMIPProjectDateTemp record</param>
    /// <returns>Project name to display for the hierarchical grid record</returns>
    display ProjIdAndName displayProjects(PMIPProjectDateTemp _record)
    {
        const str tripleSpaceCharacter = '   ';
        str leadingSpace = '';
        ProjTable projectTable;
        PMIPProjectsSorting localSort = PMIPProjectsSorting::findRecId(_record.RefSortRecId);
        
        select * from projectTable where projectTable.RecId == localSort.RefProjTable;
        ProjId localProjId = projectTable.ProjId;
        
        for (int i = 1; i < localSort.ProjHierarchyLevel; i++)
        {
            leadingSpace += tripleSpaceCharacter;
        }
        ProjIdAndName displayProjName = '';
        ProjTable localProj = ProjTable::find(localProjId);
        if (localProj)
        {
            displayProjName = leadingSpace + localProj.ProjId + ' : ' + localProj.Name;
        }
        if(localSort.RefProjTable == refAllProjectsRecId)
        {
            displayProjName = '@AXP:AXP4189';
        }
        return displayProjName;
    }
    /// <summary>
    /// Initializes the data in the PMIPProjectDateTemp based on the hierarchy from PMIPProjectsSorting Table
    /// </summary>
    public void init()
    {
        super();
        PMIPProjectDateTemp projectDateTemp;
        PMIPProjectsSorting localProjTableSorting,localProjTableSortingLoc;
    
        delete_from projectDateTemp;
        projectDateTemp.clear();
        projectDateTemp.initValue();
        PMIPProjectDateTemp.linkPhysicalTableInstance(projectDateTemp);
    
        select * from localProjTableSorting
            where localProjTableSorting.Partition == getCurrentPartitionRecId()
            && localProjTableSorting.DataAreaId == curExt()
            && localProjTableSorting.RefProjTable == refAllProjectsRecId
            && localProjTableSorting.RefRootProjTable == refAllProjectsRecId
            && localProjTableSorting.MainProjId == projTableLoc.PMIPRootProjId;
        if(localProjTableSorting.RecId)
        {
            projectDateTemp.RefRecId = localProjTableSorting.RefProjTable;
            projectDateTemp.RefSortRecId = localProjTableSorting.RecId;
            projectDateTemp.RefNodeId = localProjTableSorting.RefProjTable;
            projectDateTemp.Expand = 1;
            projectDateTemp.RefTableId = tableNum(ProjTable);
            projectDateTemp.RefRootProjTableSub = localProjTableSorting.RefRootProjTableSub;
            projectDateTemp.Visible = (localProjTableSorting.RefRootProjTable == localProjTableSorting.RefProjTable)?1:0;
            projectDateTemp.insert();
        }
        PMIPProjectDateTemp.setTmpData(projectDateTemp);
    }
    /// <summary>
    ///
    /// </summary>
    public void executeQuery()
    {
        if (true)
        {
            Query query = this.query();
            QueryBuildDataSource hierarchyTempDS = SysQuery::findOrCreateDataSource(query, tableNum(PMIPProjectDateTemp));
            SysQuery::findOrCreateRange(hierarchyTempDS, fieldnum(PMIPProjectDateTemp, Visible)).value(SysQuery::value(FalseTrue::True));
            QueryBuildDataSource sortDS = SysQuery::findOrCreateDataSource(query, tableNum(PMIPProjectsSorting));
            sortDS.clearLinks();
            sortDS.addLink(fieldNum(PMIPProjectDateTemp, RefSortRecId), fieldNum(PMIPProjectsSorting, RecId), hierarchyTempDS.name());
            query.clearOrderBy();
            sortDS.addSortField(fieldNum(PMIPProjectsSorting,REFROOTPROJTABLE),SortOrder::Ascending);
            for (int i = 1; i <= 10; i++)
            {
                sortDS.addOrderByField(fieldName2Id(tableNum(PMIPProjectsSorting), 'HierarchyLevel' + int2Str(i)), SortOrder::Ascending);
            }
            QueryRun queryRun = new QueryRun(query);
            this.queryRun(queryRun);
            super();
            ProjTable localSelect = ProjTable::find(selectedProjectId);
            if (localSelect)
            {
                PMIPProjectDateTemp temp = PMIPProjectDateTemp.findByReferenceV2(localSelect.RecId);
                if (temp)
                {
                    element.args().lookupRecord(temp);
                }
            }
        }
    }


Thank you
Badri


 
I have the same question (0)
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
     
    Try to remove setTemp method and move linkPhysicalTableInstance method to the end instead of setTemp method.
     
     
    Check the following blogs: 
     
     
     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

  • BADRI NARAYANAN G Profile Picture
    211 on at
    Thanks Waed for your response.

    As you suggested I tried to remove the setTmpData() method and add the linkPhysicalTableInstance method in the end after inserting the data in the temp table.Still it is not working.

    Also I tried the approach where you mentioned to remove the code in init method and write it in execute query method.That approach also didn't work.Please let me know your inputs.

    This is the modified code.
     
    public void init()
    {
        super();
        PMIPProjectsSorting localProjTableSorting,localProjTableSortingLoc;
        PMIPProjectDateTemp projectDateTemp;
            
        delete_from projectDateTemp;
        projectDateTemp.clear();
        projectDateTemp.initValue();
        
        select * from localProjTableSorting
            where localProjTableSorting.Partition == getCurrentPartitionRecId()
            && localProjTableSorting.DataAreaId == curExt()
            && localProjTableSorting.RefProjTable == refAllProjectsRecId
            && localProjTableSorting.RefRootProjTable == refAllProjectsRecId
            && localProjTableSorting.MainProjId == projTableLoc.PMIPRootProjId;
        if(localProjTableSorting.RecId)
        {
            projectDateTemp.RefRecId = localProjTableSorting.RefProjTable;
            projectDateTemp.RefSortRecId = localProjTableSorting.RecId;
            projectDateTemp.RefNodeId = localProjTableSorting.RefProjTable;
            projectDateTemp.Expand = 1;
            projectDateTemp.RefTableId = tableNum(ProjTable);
            projectDateTemp.RefRootProjTableSub = localProjTableSorting.RefRootProjTableSub;
            projectDateTemp.Visible = (localProjTableSorting.RefRootProjTable == localProjTableSorting.RefProjTable)?1:0;
            projectDateTemp.insert();
        }
        PMIPProjectDateTemp.linkPhysicalTableInstance(projectDateTemp);
    }

    Thanks 
    Badri
     
  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at
    Hi Badri,

    Can you share more information about the control for the display method on the form? Where is it placed and what properties are set?
  • BADRI NARAYANAN G Profile Picture
    211 on at
    Hi Andre , thanks for your response.

    Below screenshot highlights the formcontrol with the temp table datasource.



    The below screenshot highlights the grid with the temp table datasource attached to it.


    The last screenshot below shows the form where this display method will be displayed.Please let me know your inputs.



    Thanks
    Badri
  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at
    Some parts of your code are strange and/or overcomplicated. For example, you use both setTmpData() (as if your table was InMemory) and linkPhysicalTableInstance() (as if it was TempDB table), but it can't be both InMemory and TempDB at the same time. You need to decide which type you want and throw away code irrelevant to the given type. But in your case, you don't need either; you can write directly to the existing buffer.
     
    Changing QueryRun in executeQuery() is uneccesary (and potentially wrong). And a lot of code there can be simlified. Some belong to another data source. Use a table relatation instead of addLink().
     
    I would use something like this: 
    [DataSource]
    class PMIPProjectDateTemp
    {
        /// <summary>
        /// Gets the project name to display in the hierarchical grid
        /// ProjId:Name
        /// </summary>
        /// <param name = "_record">PMIPProjectDateTemp record</param>
        /// <returns>Project name to display for the hierarchical grid record</returns>
        display ProjIdAndName displayProjects(PMIPProjectDateTemp _record)
        {
            PMIPProjectsSorting localSort = PMIPProjectsSorting::findRecId(_record.RefSortRecId);
    
            ProjIdAndName displayProjName;
    
            if (localSort.RefProjTable == refAllProjectsRecId)
            {
                displayProjName = "@AXP:AXP4189";
            }
            else
            {
                ProjTable projTable = ProjTable::findRecId(localSort.RefProjTable);
                str leadingSpace = strRep(' ', localSort.ProjHierarchyLevel * 3);
                displayProjName = strFmt(%1%2 : %3, leadingSpace, projTable.ProjId, projTable.Name;
            }
    
            return displayProjName;
        }
        /// <summary>
        /// Initializes the data in the PMIPProjectDateTemp based on the hierarchy from PMIPProjectsSorting Table
        /// </summary>
        public void init()
        {
            super();
    
            PMIPProjectsSorting localProjTableSorting;
        
            select localProjTableSorting
                // You table surely isn't shared across partitions
                //where localProjTableSorting.Partition == getCurrentPartitionRecId() 
                // Are you sure that your table is shared across companies. If it isn't, this code should be removed.
                where localProjTableSorting.DataAreaId == curExt()
                && localProjTableSorting.RefProjTable == refAllProjectsRecId
                && localProjTableSorting.RefRootProjTable == refAllProjectsRecId
                && localProjTableSorting.MainProjId == projTableLoc.PMIPRootProjId;
                
            if (localProjTableSorting.RecId)
            {
                //TOOD: move to initFromProjTableSorting()
                projectDateTemp.RefRecId = localProjTableSorting.RefProjTable;
                projectDateTemp.RefSortRecId = localProjTableSorting.RecId;
                projectDateTemp.RefNodeId = localProjTableSorting.RefProjTable;
                projectDateTemp.Expand = 1;
                projectDateTemp.RefTableId = tableNum(ProjTable);
                projectDateTemp.RefRootProjTableSub = localProjTableSorting.RefRootProjTableSub;
                projectDateTemp.Visible = localProjTableSorting.RefRootProjTable == localProjTableSorting.RefProjTable;
                projectDateTemp.insert();
            }
    
        }
        
        public void init()
        {
            super();
        
            QueryBuildRange visibleRange = this.queryBuildDataSource().addRange(fieldNum(PMIPProjectDateTemp, Visible)).value(queryValue(true));
            visibleRange.status(RangeStatus::Locked);
        }
        
        public void executeQuery()
        {
            super();
    
            if (localSelect)
            {
                PMIPProjectDateTemp temp = PMIPProjectDateTemp.findByReferenceV2(ProjTable::getProjRecId(selectedProjectId));
                if (temp)
                {
                    this.positionToRecord(temp);
                }
            }
        }
    }
        
    [DataSource]
    class PMIPProjectsSorting
    {
        public void init()
        {
            QueryBuildDataSource qbds = this.queryBuildDataSource();
            
            qbds.addOrderByField(fieldNum(PMIPProjectsSorting, RerRootProjTable));
            
            for (int i = 1; i <= 10; i++)
            {
                qbds.addOrderByField(fieldName2Id(tableNum(PMIPProjectsSorting), 'HierarchyLevel' + int2Str(i)));
            }
        }
    }
    It might fix your current problem as well and if not, we'll at least deal with simpler and more meaningful code.
     
    Forgive me possible bugs in code; I wrote it outside IDE.
     
    Now I see your code will insert either a single record or none at all. Does it insert one in your case? Use the debugger to find it out. Are you sure that you don't want more than one?
  • BADRI NARAYANAN G Profile Picture
    211 on at
    Hi Martin,Thanks for response.

    Actually depending on the number of projects present in the hierarchy the grid will be displayed.Originally the insertion of records in temp table was done using SQL statements but since it was not working I tried to do it normally with X++ code but still it did not work.Modified the code as per your changes but still the display method is not filled with records.

    I will share below the original code which performs insertion through SQL statements.Please give me your inputs on this.I tried to print the records using info method after insertion of records to temp table and it is showing the record count but in the display method of temp table datasource the record is always empty.This is the code present in init method and the insertion logic present in another class but called using static method.I have attached the init method and the insertion static methods named initializeProjHierarchyTempAllProjects and 
    initializeProjHierarchyTemp.
     
     public void init()
     {
         super();
         PMIPProjectDateTemp projectDateTemp;
         PMIPProjectsSorting localProjTableSorting,localProjTableSortingLoc;
     
         delete_from projectDateTemp;
         projectDateTemp.clear();
         projectDateTemp.initValue();
         PMIPProjectDateTemp.linkPhysicalTableInstance(projectDateTemp);
     
         PMIPSimpleAdjustmentsProjectsHelper::initializeProjHierarchyTempAllProjects(projectDateTemp.getPhysicalTableName(),
    int2Str(refAllProjectsRecId),refAllProjectsRecId,projTableLoc.PMIPRootProjId);
     
         while select * from localProjTableSortingLoc
             where localProjTableSortingLoc.RefAllProjecsIds == refAllProjectsRecId
             && localProjTableSortingLoc.MainProjId == projTableLoc.PMIPRootProjId
         {
             ProjTable ProjTableRec = ProjTable::findRecId(localProjTableSortingLoc.RefProjTable);
             PMIPSimpleAdjustmentsProjectsHelper::initializeProjHierarchyTemp(localProjTableSortingLoc.RefRootProjTable, projectDateTemp.getPhysicalTableName(), ProjTableRec.ProjId,refAllProjectsRecId, projTableLoc.PMIPRootProjId);
         }

         PMIPSimpleAdjustmentsProjectsHelper::expandAllParentsOfCurProjAndMakeItVisible(int2Str(refAllProjectsRecId), projectDateTemp.getPhysicalTableName(),refAllProjectsRecId, projTableLoc.PMIPRootProjId);
     }

     
    public static void initializeProjHierarchyTempAllProjects(
        str _tempTablePhysicalName,
        ProjId _curProjId, int _refAllProjectsRecId, ProjId _mainProjId)
    {
        Partition currentPartition = getCurrentPartitionRecId();
        DataAreaId currentCompany = curExt();
        RecId curProjRecId = _refAllProjectsRecId;
     
        // Construct a query to insert all (ProjTable) records from billing schedule line into the temp table

        str insertTempSQL = strFmt(@"INSERT INTO %1 (
                                        Partition, DataAreaId, RefRecId, RefSortRecId, RefNodeId, Expand, Visible, RefTableId, RefRootProjTableSub
                                    ) SELECT
                                        %2, '%3', %4, Sort.RecId, %4, 1, IIF(Sort.RefRootProjTable = Sort.RefProjTable, 1, 0), '%6', Sort.RefRootProjTableSub
                                    FROM  PMIPProjectsSorting AS Sort WHERE
                                        Sort.Partition = %2 AND Sort.DataAreaId = '%3'
                                        AND Sort.RefProjTable = %4 AND Sort.RefRootProjTable = %4
                                        AND Sort.RefProjTable = %7
                                        AND Sort.MainProjId = '%8'",
                                    _tempTablePhysicalName,
                                    currentPartition,
                                    currentCompany,
                                    _refAllProjectsRecId,
                                    int2Str(_refAllProjectsRecId),
                                    TableNum(ProjTable),
                                    curProjRecId,
                                    _mainProjId);
     
        PMIPSimpleAdjustmentsProjectsHelper::executeSQLStatement(insertTempSQL);
    }
     
     
     
    public static void initializeProjHierarchyTemp(
        RecId _refRootProjTable,
        str _tempTablePhysicalName,
        ProjId _curProjId,int _refAllProjectsRecId, ProjId _mainProjId)
    {
        Partition currentPartition = getCurrentPartitionRecId();
        DataAreaId currentCompany = curExt();
        ProjTable rootProjTable = ProjTable::findRecId(_refRootProjTable);
        RecId curProjRecId = ProjTable::find(_curProjId).RecId;
     
        // Construct a query to insert all (ProjTable) records from billing schedule line into the temp table

        str insertTempSQL = strFmt(@"INSERT INTO %1 (
                                        Partition, DataAreaId, RefRecId, RefSortRecId, RefNodeId, Expand, Visible, RefTableId,                 RefRootProjTableSub,RefAllProjecsIds
                                    ) SELECT
                                        %2, '%3', P1.RecId, Sort.RecId, P1.RecId, IIF(Sort.RefRootProjTable = Sort.RefProjTable, 1, 0), IIF(Sort.RefRootProjTable =      Sort.RefProjTable OR P1.ParentId = '%5', 1, 0), '%6', Sort.RefRootProjTableSub, %8
                                    FROM ProjTable AS P1
                                    INNER JOIN PMIPProjectsSorting AS Sort ON
                                        Sort.Partition = %2 AND Sort.DataAreaId = '%3'
                                        AND Sort.RefProjTable = P1.RecId AND Sort.RefRootProjTable = %4
                                    WHERE
                                        P1.Partition = %2 AND P1.DataAreaId = '%3' AND P1.RecId = %7
                                        AND Sort.MainProjId = '%9'",
                                    _tempTablePhysicalName,
                                    currentPartition,
                                    currentCompany,
                                    _refRootProjTable,
                                    rootProjTable.ProjId,
                                    TableNum(ProjTable),
                                    curProjRecId,
                                    _refAllProjectsRecId,
                                    _mainProjId);
     
        PMIPSimpleAdjustmentsProjectsHelper::executeSQLStatement(insertTempSQL);
    }
     
     
    Thanks 
    Badri
  • Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
     
    Can you try to comment all the code on the display method and return any static string? Give it a try and tell us if the static value will appear or not?
     
     
    Thanks,
    Waed Ayyad
  • BADRI NARAYANAN G Profile Picture
    211 on at
    Hi Waed.

    I commented all the code in display method and tried to print a static text it is printing as given in the display method.




    Thanks 
    Badri
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
     
    It seems the issue on your logic inside the display method, did you try to trace the code? and see if the data is returned or not?
     
     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at
    Your other code sniipet seems to confirm that you want to insert more than a single record. You has a while select in your original code, but you don't have such logic in your current code, therefore that's a bug.
     
    I think your about the number of records refer to the original code, as it doesn't make a good sense in your current one. And therefore we don't know whether your current code in init() created a record or not. Please put a breakpoint to the init() method and check whether any record gets inserted to PMIPProjectDateTemp. If not, there is no point running the rest of the code and checking whether what the display method returns, because you already know that there is no data.
     
    I know that your screenshot shows a record, but it may be about some other data source. It depends on the implementation of the form, which isn't known to me.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans