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

Table Exist method with multiple arguments

(0) ShareShare
ReportReport
Posted on by 99

Hi everyone,

so i have created a table that have fields that it gets from two different tables with foreing key relations or table methods, the table I created have a primary index that is the combination of two fields (every value in the table can exist multiple times and I wanted on the combination of two fields to be unique) so my question is: how to create the exist method that uses these two fields of the primary index to determine if a record exist ?

This is what i tried out but it returns multiple errors:

<> static boolean exist(ILBMaterialCode _materialCode, ItemIdBase _itemId)
{
ILBReleasedProductMaterials iLBReleasedProdMat;
boolean vExist = boolean::false;
if(_materialCode)
{
if(_itemId)
{
vExist = boolean::true;
}
}
return vExist && (select firstonly RecId iLBReleasedProdMat
index hint ProductMaterialsIdx
where iLBReleasedProdMat.MaterialCode == _materialCode &&
iLBReleasedProdMat.ProductNumber == _itemId).RecId != 0;
}

</>

I appreciate every bit of help I can get ^^.

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi Fares,

    I would say that the first step is to read the errors and try to understand what they mean. If you need help with them, please share them with us.

    I can see right away that you have syntax errors in your code, for example "boolean::false".

    You should find plenty of examples of "exist" methods throughout the system. To me it looks that you have already everything that is needed to solve your problem, but you should clean up unnecessary and wrong code away from your method. But if you have any doubts, please remember to share your new code, as well as any errors and other details with us. Thanks!

    static boolean exist(ILBMaterialCode _materialCode, ItemIdBase _itemId)
    {
        return  (select firstonly RecId from ILBReleasedProductMaterials
        where ILBReleasedProductMaterials.MaterialCode == _materialCode &&
        ILBReleasedProductMaterials.ProductNumber == _itemId).RecId != 0;
    }
    
    
    

  • Fares Ben Miled Profile Picture
    99 on at

    Thanks Nikolaos, I did actually check the custtable ones and I noticed that they return something like this :

        static boolean exist(CustAccount _custAccount)
        {
            return _custAccount && (select firstonly RecId from custTable
                                        index hint AccountIdx
                                        where custTable.AccountNum == _custAccount).RecId != 0;
        }

    or this: 

        public static boolean existDlvMode(DlvModeId _dlvModeId)
        {
            CustTable       custTable;
    
            if (_dlvModeId == '')
            {
                return false;
            }
    
            select firstonly
                RecId from custTable
            where
                custTable.DlvMode == _dlvModeId;
    
            return (custTable.RecId != 0);
        }

    which got me confused on when to use the parameters in the return value to assess with and when to use table buffer (still new to the x so I'm still learning ^^)

    If you can explain more on my confusion I would really appreciate it, thanks again .

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    You can use either approach. The only difference is that with your latest examples, the system doesn't perform a database call if an empty string is provided as _custAccount or _dlvModeId parameter. So, if you expect that your method is often called with empty parameters, you can implement such solution to prevent unnecessary database calls.

    Of course assuming that your key fields in the table are mandatory and can't have empty values. If they can have empty values, then you should always do the database call.

    I would say that what we have discussed here is not specific to x++, it's very common level logic, even though we have implemented it in x+ because we work with Dynamics.

  • Fares Ben Miled Profile Picture
    99 on at

    Thanks again, you worded it clearly and I appreciate your help and time.

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