Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Error on Lookup

Posted on by 49
Hi I do have a lookup on a custom field on the sales table. It´s a lookup on a custom table
 
The lookup open like it should be, I can filter on all 4 Lookup fields but when I select a value I get an error that the value cannot be found
 
    sysTableLookup=SysTableLookup::newParameters(tablenum(CEM_CRM_Opportunity),this);    sysTableLookup.addLookupfield(fieldnum(CEM_CRM_Opportunity,Name));    sysTableLookup.addLookupfield(fieldnum(CEM_CRM_Opportunity,Opportunitynumber));    sysTableLookup.addLookupfield(fieldnum(CEM_CRM_Opportunity,StatusA));    sysTableLookup.addLookupfield(fieldnum(CEM_CRM_Opportunity,StatusB));    sysTableLookup.addLookupfield(fieldnum(CEM_CRM_Opportunity,OpportunityId));    qbds = query.addDataSource(tablenum(CEM_CRM_Opportunity));    sysTableLookup.parmQuery(query);    sysTableLookup.performFormLookup();
I open the lookup, filter on the name column and select the record.
 
Now the error comes up:
The value '52451 SKARPSKYTTEN, LUND' in field 'Opportunity Id' is not found in the related table 'Opportunity'.
 
  • Suggested answer
    Cembrit Profile Picture
    Cembrit 49 on at
    Error on Lookup
    sorry wrong post but am not able to delete it
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    Error on Lookup
    Then you must return the value of OpportunityId instead of Name. Use the second parameter of addLookupField():
    sysTableLookup.addLookupField(fieldNum(CEM_CRM_Opportunity, OpportunityId), true);
  • Cembrit Profile Picture
    Cembrit 49 on at
    Error on Lookup
    I am sorry.
     
    The related field on the customized table is the guid (because it is the only unique field)
    The search in the lookup is easier by name that's where the text (52451...) comes from.

    The lookup contains multiple fields but when selection should be done on the responiding guid (opportunity id)
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    Error on Lookup
    OK, so you're saying that the value you selected in the lookup ('52451 SKARPSKYTTEN, LUND') is indeed invalid and it can't be used in the field. You're saying that you must use a GUID there, not something like '52451 SKARPSKYTTEN, LUND'.
     
    Unfortunately you haven't answer the question about the related field, therefore I can't tell us which field contains the GUID and therefore it needs to be returned by the lookup. Also, I think the a better design would be using a relation over RecId instead of the GUID, if it meets your other requirements. Then you can simply select the field group that should be shown in the lookup and the system will create the lookup; you won't need any code.
  • Cembrit Profile Picture
    Cembrit 49 on at
    Error on Lookup
    Hi
     
    Entering the opportunity id (GUID from CRM System) directly works fine. 
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    Error on Lookup
    I guess that then problem is not in the lookup, but in what values are allowed for the table field (as defined by a table relation). Are you sure that the field has a relation to CEM_CRM_Opportunity? If so, which field is it related to?
     
    You can also test it by typing the value in the field without using a lookup. If it fails too, you'll know for sure that it has nothing to do with the lookup.
  • Cembrit Profile Picture
    Cembrit 49 on at
    Error on Lookup
    Hi Andre

    Yes the value "52451 SKARPSKYTTEN, LUND" is the name the user are filtering the lookup.

    Addid the addSelectionField does not change anything. the error still occurs
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,253 Super User 2024 Season 2 on at
    Error on Lookup
    Hi Cembrit,
     
    It would be good to know where the value "52451 SKARPSKYTTEN, LUND" is coming from. Is this the opportunity name? 
    You can try changing the command for adding the lookup field for the Opportunity ID to a selection field. That will tell the lookup to use another field than the first one.
     
    sysTableLookup.addSelectionfield(fieldnum(CEM_CRM_Opportunity,OpportunityId)); 
     
     
     

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans