Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Error on Lookup

Posted on by 47
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 47 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 225,864 Super User 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 47 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 225,864 Super User 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 47 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 225,864 Super User 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 47 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... 288,584 Super User 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)); 
     
     
     

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin DrĂ¡b Profile Picture

Martin DrĂ¡b 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans