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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How can i return the RECID from a selected record

(0) ShareShare
ReportReport
Posted on by

Hey,

how can i return the RECID from a selectede record.
I try it with this code but it does not work.

  int64 stiRecId;
     str stiRecIdStr;
    ;

    //TODO Anfrage um bestellt durch erweitern mund ggf. Status != Übernommen
    select salesTableImport
        where salesTableImport.CustAccount == account
            && salesTableImport.OrderedBy == orderedBy;
        
  
    stiRecId        = salesTableImport.RecId;
    stiRecIdStr     = int642str(stiRecId);

    if(salesTableImport.RecId != 0)
    {
     //   return salesTableImport;
        //Info('Kopf ist bereits vorhanden');
    }


Thanks for help.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    The simplest AX syntax is more or less this: select FIELDLIST from TABLE where CRITERIA.

    If you do not provide a FIELDLIST, it pulls back all fields, including RecId.

    If you do not have a value, it means that either your table is empty, or you do not have a value matching your selection CRITERIA in the statement.

    Or you may be in the wrong company account, probably forgot to switch from the default DAT legal entity in your dev workspace.

  • Community Member Profile Picture
    on at

    The if() statement works fine.

    My only problem is that i cant return the recId.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    I am unsure what do you mean by return, please clarify.

    The returned value of a method must match what has been defined as the method return value. If you want to return RecId, it must be of type RecId as well. Unfortunately you did not paste that, so we cannot tell if that is the problem. For example:

    public RecId dosomething()

    {

        RecId test = 123456;

        return test;

    }

  • Community Member Profile Picture
    on at

    i select() a record with the select code.

    I get a record and i can query the recId from the record.

    but I want to give it back to the previous class / methods.

    Exmaple

    retrun salesTableImport.recId;

    So my question is how is the syntax to return the recId from the selected record.

    Thank you for help.

  • XB Profile Picture
    1,875 on at
    Where are you doing this?

    It's works if you have records.

    select recId
    from salesTableImport where salesTableImport.CustAccount == account && salesTableImport.OrderedBy == orderedBy; return salesTableImport.recId;
  • Community Member Profile Picture
    on at

    I have a record and get a recId too.

    But i can not return them.

    If i try this code : return salesTableImport.recId;

    I get an error:  The operand is not compatible with the type of function

    What do you mean with 'Where are you doing this ?' ?

    I do this in a method of my class, where i create recrods.

  • XB Profile Picture
    1,875 on at

    So I suposse you have something like

    public RECID functionName()

    {

    select recId

           from salesTableImport

           where salesTableImport.CustAccount == account

               && salesTableImport.OrderedBy == orderedBy;

      return salesTableImport.recId;

    }

  • Community Member Profile Picture
    on at

    No i do this all in this method,

    void createSalesTableImport()
    {
         int64 stiRecId;
         str stiRecIdStr;
        ;
    
        //TODO Anfrage um bestellt durch erweitern mund ggf. Status != Übernommen
        select salesTableImport
            where salesTableImport.CustAccount == account
                && salesTableImport.OrderedBy == orderedBy;
    
    
        stiRecId        = salesTableImport.RecId;
        stiRecIdStr     = int642str(stiRecId);
    
        if(salesTableImport.RecId != 0)
        {
            return salesTableImport;
            //Info('Kopf ist bereits vorhanden');
        }
        else if(salesTableImport.RecId == 0)
        {
    
            datum = today();
    
            salesTableImport.clear();
    
            //TODO salesTableImport.ImportId               = ;
            salesTableImport.companyGLN             = companyGLN;
            salesTableImport.CustAccount            = account;
            salesTableImport.SearchName             = searchName;
            salesTableImport.OrderedBy              = orderedBy;
            salesTableImport.Backlog                = backlog;
            salesTableImport.Email                  = email;
            salesTableImport.OrderNum               = orderNum;
        //salesTableImport.ProvisionalContractId   = provisionalContractId;
            salesTableImport.CustName               = name;
            salesTableImport.DiscReadingDate        = datum;
        //salesTableImport.ImportStatus            = importStatus;
            salesTableImport.ContractId             = contractId;
            importLineTable++;
            salesTableImport.ImportLine             = importLineTable;
    
            salesTableImport.insert();
    }
    
        //TODO SalesTableImport fehlt noch;
        //Vorläufige auftragsummer
        //ImportStatus
    
    }

    And it works i only want to return the recId that i selectetd.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Same answer as my reply. You are not returning the type you have declared.

    Void = do not return anything, no type

    You need RecId there as explained already.

  • Verified answer
    Rudi Hansen Profile Picture
    4,079 on at

    Your method is not defined to return anything. (void means do not return a value)

    And your return statement returns the table, not the tables recid (should be return salesTableImpor.recid)

    Also your method needs to return something even if no record is found, that's why i have inserted the last return line.

    So your method should look like this.

    recid createSalesTableImport()
    {
        int64 stiRecId;
        str stiRecIdStr;
        ;
    
        //TODO Anfrage um bestellt durch erweitern mund ggf. Status != Übernommen
        select salesTableImport
            where salesTableImport.CustAccount == account
                && salesTableImport.OrderedBy == orderedBy;
    
    
        stiRecId        = salesTableImport.RecId;
        stiRecIdStr     = int642str(stiRecId);
    
        if(salesTableImport.RecId != 0)
        {
            return salesTableImport.recid;
            //Info('Kopf ist bereits vorhanden');
        }
        else if(salesTableImport.RecId == 0)
        {
    
            datum = today();
    
            salesTableImport.clear();
    
            //TODO salesTableImport.ImportId               = ;
            salesTableImport.companyGLN             = companyGLN;
            salesTableImport.CustAccount            = account;
            salesTableImport.SearchName             = searchName;
            salesTableImport.OrderedBy              = orderedBy;
            salesTableImport.Backlog                = backlog;
            salesTableImport.Email                  = email;
            salesTableImport.OrderNum               = orderNum;
        //salesTableImport.ProvisionalContractId   = provisionalContractId;
            salesTableImport.CustName               = name;
            salesTableImport.DiscReadingDate        = datum;
        //salesTableImport.ImportStatus            = importStatus;
            salesTableImport.ContractId             = contractId;
            importLineTable++;
            salesTableImport.ImportLine             = importLineTable;
    
            salesTableImport.insert();
    	}
        return salesTableImport.recid;  // Inserted so the method returns something no matter what.
    
        //TODO SalesTableImport fehlt noch;
        //Vorläufige auftragsummer
        //ImportStatus
    
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans