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

The Record Has Never Been Selected - smmActivities

(0) ShareShare
ReportReport
Posted on by 5

I have a piece of code that works 90% the other 10% occasionally it breaks and I receive the "record has never been selected" error. I've checked smmActivities table up and down and while I'm sure there's something I'm missing it just isn't evident to me. Is there something my code is missing? Why does it work sometimes and other times it doesn't?

This code is meant to reassign open activities to a worker when assigned to new territory.

Thanks in advance,

Doug

static void AssignActivitiesByCustomer(Args _args)
{
    CustTable                   _custTable;
    smmActivityParentLinkTable  _smmActivityParentLinkTable;
    smmActivities               _smmActivities;


    while select *  from _custTable where _custTable.MainContactWorker == HcmWorker::findByPersonnelNumber("000297").RecId
    {
        while select * from _smmActivityParentLinkTable where _smmActivityParentLinkTable.RefTableId == 77 && _smmActivityParentLinkTable.RefRecId == _custTable.RecId
        {
            _smmActivities = smmActivities::find(_smmActivityParentLinkTable.ActivityNumber, true);
             if(_smmActivities.Closed == NoYes::No)
            {
                if(_custTable.MainContactWorker != _smmActivities.ResponsibleWorker)
                {
                    _smmActivities.ResponsibleWorker = _custTable.MainContactWorker;
                    _smmActivities.update();

                }
            }

        }
    }
info("Complete");
}

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hio Doug,

    Maybe there are no matching smmActivities records for the times they are failing. You can have a check for that to get rid of this error -

    static void AssignActivitiesByCustomer(Args _args)
    {
        CustTable                   _custTable;
        smmActivityParentLinkTable  _smmActivityParentLinkTable;
        smmActivities               _smmActivities;
    
    
        while select *  from _custTable where _custTable.MainContactWorker == HcmWorker::findByPersonnelNumber("000297").RecId
        {
            while select * from _smmActivityParentLinkTable where _smmActivityParentLinkTable.RefTableId == 77 && _smmActivityParentLinkTable.RefRecId == _custTable.RecId
            {
                _smmActivities = smmActivities::find(_smmActivityParentLinkTable.ActivityNumber, true);
                 if(_smmActivities && _smmActivities.Closed == NoYes::No)
                {
                    if(_custTable.MainContactWorker != _smmActivities.ResponsibleWorker)
                    {
                        _smmActivities.ResponsibleWorker = _custTable.MainContactWorker;
                        _smmActivities.update();
    
                    }
                }
    
            }
        }
    info("Complete");
    }

  • Verified answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    Add a condition to check if _smmActivities exists.

    static void AssignActivitiesByCustomer(Args _args)
    {
        CustTable                   _custTable;
        smmActivityParentLinkTable  _smmActivityParentLinkTable;
        smmActivities               _smmActivities;
    
    
        while select *  from _custTable where _custTable.MainContactWorker == HcmWorker::findByPersonnelNumber("000297").RecId
        {
            while select * from _smmActivityParentLinkTable where _smmActivityParentLinkTable.RefTableId == 77 && _smmActivityParentLinkTable.RefRecId == _custTable.RecId
            {
                _smmActivities = smmActivities::find(_smmActivityParentLinkTable.ActivityNumber, true);
                 if(_smmActivities && _smmActivities.Closed == NoYes::No)
                {
                    if(_custTable.MainContactWorker != _smmActivities.ResponsibleWorker)
                    {
                        _smmActivities.ResponsibleWorker = _custTable.MainContactWorker;
                        _smmActivities.update();
    
                    }
                }
    
            }
        }
    info("Complete");
    }

  • Suggested answer
    Mohsin Khalid Profile Picture
    501 on at

    Doug what you can also do is  refresh the _smmActivites buffer before you set the reference. There is a bug in X++ on using same buffers for different values in while loops. add line below before line 12

    _smmActivities.refresh();

    _smmActivities = smmActivities::find(_smmActivityParentLinkTable.ActivityNumber, true);

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Doug,

    Have you checked if you have orphaned records in smmActivityParentLinkTable with non existing activityNumber (you can create non exist join query to check it)? There could be some process that deletes activity without cleaning linkTable and it's causing issues in your code.

    As a quick solution, you can check if activity exists, but who know how the system will behave in other processes.

  • Doug E. Profile Picture
    5 on at

    Thanks for the quick response everyone! Adding the check for existing records allowed me to proceed with the job for this user.

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 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans