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

How to get the ID from a lookup field

(0) ShareShare
ReportReport
Posted on by 843

Hello,

I am working on a form that has a standard lookup field that is used to select a vendor. When expanded, the lookup shows the name and vendor ID. When the appropriate vendor is selected, only the name is shown in the form field.

And now, based on this vendor selection, I want the second lookup field to show all addresses assigned to the recipient. I have already written the code for FormControlEventType::Lookup and it works, I just need to get the vendorID. I can refer to the name of the vendor that is selected, but for it to work properly I need ID.

str VendorName = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, DirPartyTable_Name)).valueStr();

How can I get the ID of the recipient from the first lookup, on the format only the name of the recipient is available?

Thanks.

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi Shooowtek,

    Lookup field will return the value that is added first in the add lookup field method.

    If you want vendor id field you need to write lookup event handler for vendor lookup and in the lookup method you need to add vendor ID and then name to the addLookupField method.

    Also you need to cancel the super call using the form control cancel event arguments. 

    Thanks,

    Girish S.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    It's a Reference Group. At that lookup You are selecting CaseDetailBase.Party field (DirPartyTable.RecId). You can use this field to find DirPartyTable

  • Shooowtek Profile Picture
    843 on at

    Hello ergun sahin 

    How do I select CaseDetailBase.Party field?

    Could you please suggest how to refer to the PartyID, when after selecting the value, I have only the name returned?

    776816.png

    6560.png

    As I mentioned earlier, I can get the name, but it does not meet the requirements..

    str CompanyName = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, DirPartyTable_Name)).valueStr();

    Thanks.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Refer to the "Party" field of CaseDetailBase data source.

  • Shooowtek Profile Picture
    843 on at

    Yes, but here there is still no insertion in CaseDetailBase.

    Based on the "Name" field and the selected company, I'am to display all addresses in the next lookup. Therefore, I need to find the ID of the organization, not the name.

    If I refer to "sender.formRun().design().controlName" I get the value as a string and can't do anything with it.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    You seem to be missing my point. I'm talking neither about an insertion nor the name.

    Party ID field contains a RecId (= an automatically generated unique identifier) of a DirPartyTable record. It's not the name.

  • Shooowtek Profile Picture
    843 on at

    I understand this. I haven't been clear. I don't know how to get the partyId I need to searching for addresses in another lookup on this form. I don't want to search by name.

    I know there is a RecId in the party ID field, but how do I get to it?

    Thanks for any suggest.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    To be able to adjust your code, I need to know what you have in the sender variable. If it's an event handler for a standard control, it's enough if you tell me the name of the control - they'll be able to find details by myself. If it's a custom control, please tell me its type and which data source it's bound to (if any).

  • Shooowtek Profile Picture
    843 on at

    This is my first erroneous version of the code:

    [FormControlEventHandler(formControlStr(CaseDetailCreate, CaseDetailBase_myCustAddress), FormControlEventType::Lookup),
        SuppressBPWarning('BPParameterNotUsed', 'False positive')]
        public static void CaseDetailBase_myCustAddress_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            SysTableLookup sysTableLookup;
            QueryBuildDataSource queryBuildDataSource;
            QueryBuildRange queryBuildRange;
            str partyName = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, DirPartyTable_Name)).valueStr();
    
            Query query;
    
            SysTableLookup = SysTableLookup::newParameters(tableNum(DirPartyPostalAddressView), sender);
            sysTableLookup.addLookupfield(fieldNum(DirPartyPostalAddressView, Address));
            sysTableLookup.addLookupfield(fieldNum(DirPartyPostalAddressView, LocationName));
    
            query = new Query();
            queryBuildDataSource = query.addDataSource(tableNum(DirPartyPostalAddressView));
            queryBuildRange = queryBuildDataSource.addRange(fieldNum(DirPartyPostalAddressView, LocationName));
            queryBuildRange.value(partyName);
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
    
            FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;
    
            event.CancelSuperCall();
        }

    CaseDetailBase_myCustAddress - FormStringControl

    Thanks.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    All right, now please tell me which data source it's bound to (if any). The name looks like it's bound to CaseDetailBase data source - is it a correct assumption?

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans