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 :
Microsoft Dynamics CRM (Archived)

Getting error "UserId is empty guid" while updating userlookup

(0) ShareShare
ReportReport
Posted on by 111

Hi all,

I'm getting error when i try to set userlookup. Kindly help.

below is the code to update an user lookup field in quote entity.

if (userList.Entities.Count > 0)
{
EntityReference _user = new EntityReference(userList.Entities[0].LogicalName, userList.Entities[0].Id);
//this.user.Set(executioncontext, _user); new_levelapprovaluser
QueryExpression queryqd = new QueryExpression("quote");
queryqd.ColumnSet.AddColumns("new_levelapprovaluser");
queryqd.Criteria.AddCondition("quoteid", ConditionOperator.Equal, entity.Id);
EntityCollection qd = service.RetrieveMultiple(queryqd);
foreach (Entity allrecord1 in qd.Entities)
{
allrecord1["new_levelapprovaluser"] = new EntityReference(_user.LogicalName, _user.Id); ;
service.Update(allrecord1);
}
}

Thank you

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    The following code should do what you are trying to do

       if (userList.Entities.Count > 0)

                   {

                       EntityReference _user = userList.Entities[0].ToEntityReference();

                       Entity quote = new Entity(entity.LogicalName, entity.Id);

                       quote["new_levelapprovaluser"] = _user;

                       service.Update(quote);

                   }

  • Suggested answer
    Mansoor Sulaiman Profile Picture
    4,330 on at

    Hi,

    Pls, check the value exists or not.

    Mansoor

  • Amos Dave Profile Picture
    111 on at

    Hi Kokulan,

    Thanks for you reply.

    I tried with your code. I'm getting the same error.  Once the control comes out of the service.update() it jumps to ecxception.

  • Amos Dave Profile Picture
    111 on at

    Hi Mansoor,

    Value exists.

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    If it throws an exception, could you check if there is any Inner Exception, and if there is one, please share message from that as well.

    It would be easier to spot errors if you could share the full code that does this update (Only share your code if possible).  

    Thanks

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans