Skip to main content

Notifications

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");
}

  • Doug E. Profile Picture
    5 on at
    RE: The Record Has Never Been Selected - smmActivities

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

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: The Record Has Never Been Selected - smmActivities

    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.

  • Suggested answer
    Mohsin Khalid Profile Picture
    501 on at
    RE: The Record Has Never Been Selected - smmActivities

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

  • Verified answer
    vinitgoyal2005 Profile Picture
    6,330 on at
    RE: The Record Has Never Been Selected - smmActivities

    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");
    }

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: The Record Has Never Been Selected - smmActivities

    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");
    }

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,099 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans