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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Guid contains data on ...
Power Apps
Unanswered

Guid contains data on SQL but appears null in plugin (Exception caught - Expected non-empty Guid.)

(0) ShareShare
ReportReport
Posted on by 169

Hello,

I am trying to get all members (leads) of a static marketing list in order to qualify them as Contacts.

The problem is that the guid value of members [entityid] appears to be null. The error I get is: Exception caught - Expected non-empty Guid.

 

Here is proof that entityid is not null:

 

 
 

Iro__2-1670589368550.png

 

Below is my code:

 

 

 QueryExpression queryListMembers = new QueryExpression("listmember");
 queryListMembers.Criteria.AddCondition("listid", ConditionOperator.Equal, new Guid("fb559388-f376-ed11-81ab-6045bd8f9f3b"));
 EntityCollection collectionMembers = serviceClient.RetrieveMultiple(queryListMembers);

 if(collectionMembers.Entities.Count > 0)
 {
 Console.WriteLine(collectionMembers.Entities.Count.ToString());
 foreach (Entity member in collectionMembers.Entities)

 {
 QualifyLeadRequest request = new QualifyLeadRequest();
 request.CreateAccount = false;
 request.CreateOpportunity = false;
 request.CreateContact = true;
 request.LeadId = new EntityReference("lead", member.GetAttributeValue<Guid>("entityid")); // This is null. Tried also with member.GetAttributeValue<EntityReference>("entityid").Id 
 request.Status = new OptionSetValue(3); // Qualified

 QualifyLeadResponse qualifyResponse = (QualifyLeadResponse)serviceClient.Execute(request);

 }
 }

 

 

Any help would be much appreciated

I have the same question (0)
  • cchannon Profile Picture
    4,702 Moderator on at

    Guid (while it is a valid datatype and class) is NOT a Dataverse column type. There is no such thing as a GUID column in Dataverse (at least, as far as the API is concerned). What you're seeing in SQL is an unfortunate oversimplification of what is actually known as an EntityReference.

     

    I'll elaborate on that before I offer you a solution (but the solution is coming!): in SQL, when you have a Foreign Key you always know what table is being referenced - it is an innate quality of the column itself and so you don't need anything more than the GUID to find the record your FK points to. But Dataverse actually offers more complexity than that. From a single column, you could hypothetically be referencing more than one other table (for example, the OOB Customer lookup points to BOTH Account and Contact).

     

    So, in Dataverse (in plugins) when we are talking about a Foreign Key reference, we don't use the datatype Guid. Instead, we use EntityReference. EntityReference, in turn, has three members, each of which carries some value to us: Id (the Guid), Name (the Primary column, or display name, of the record), and LogicalName (the name of the table where this record is found). The Name attribute is pretty optional - it is really only there for the convenience of developers to reduce the number of API calls we need to make - but the other two are the real identity of the record being referenced.

     

    So, all you need to do to fix your code is change 

    request.LeadId = new EntityReference("lead", member.GetAttributeValue<Guid>("entityid"));

    To

    request.LeadId = new EntityReference("lead", member.GetAttributeValue<EntityReference>("entityid").Id);
  • Morgan78 Profile Picture
    169 on at

    Dear @cchannon 

     

    First of all, thank you very much for the thorough response. It cleared the confusion I had on why I get more columns than expected on SQL and how I should get the Id from lookup fields from now on. I really appreciate it.

     

    I did try your suggestion, but now I get the "System.NullReferenceException: Object Reference not set to an instance of an object" which, I guess, indicates that the Id is null, which is weird because it is not null. What is in fact null, is the Name. Could this be the issue?

     

    Thank you 

  • cchannon Profile Picture
    4,702 Moderator on at

    That doesn't seem quite right. The whole point of using GetAttributeValue instead of just grabbing the array members by name is that it insulates you from null dereferencing errors. Maybe this OOB column is one of those weirdo MSFT first-party columns that don't follow the rules like the rest of us?

     

    Try this:

    var entityMetadataRequest = new RetrieveEntityRequest
    {
     EntityFilters = EntityFilters.Attributes,
     LogicalName = myEntity.LogicalName
    };
    
    EntityMetadata metadataResponse = (EntityMetadata)orgService.Execute(entityMetadataRequest).Results.FirstOrDefault().Value;
    
    AttributeMetadata[] attributeMetadata = metadataResponse.Attributes;
    
    tracingService.Trace(attributeMetadata.Where(x => x.LogicalName == "entityid").FirstOrDefault().AttributeTypeName.Value);

    where myEntity is your "member" entity and "tracingService" is an instantiation of the ITracingService.

     

    This should trace out for you the proper datatype of that column, just in case it is something unexpectedly weird.

  • Morgan78 Profile Picture
    169 on at

    Hi @cchannon ,
    I tried it, it returns "LookupType".

    I tried to do the same thing with Power Automate (that is, get the list members, get their entityid and qualify them as Contacts) and was successful. But I would like to do it with plugin (console app actually), because in production the list members are more than 20K records.

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 Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 525 Most Valuable Professional

#2
Haque Profile Picture

Haque 273

#3
Kalathiya Profile Picture

Kalathiya 232 Super User 2026 Season 1

Last 30 days Overall leaderboard