Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM Entity Records Sharing to User using c# Code , Entity(account) With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist .

(0) ShareShare
ReportReport
Posted on by 244

Hello All,

I written code for Share Current Records to Users,in the workflow, But when ever, code excute it throwing following error .

Code :- c#

protected override void Execute(CodeActivityContext executionContext)
       {
 
 
           IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
           IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
           IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
           ITracingService trace = executionContext.GetExtension<ITracingService>();
           
           trace.Trace("Excution is just Started....");
 
           var userIds = UserIds.Get<string>(executionContext);
           trace.Trace("UserIds String :" + userIds);
           string[] userIdList = userIds.ToString().Split(';');
           for(int i=0;i< userIdList.Length;i++)
           {
               trace.Trace("User Ids:" + userIdList[i]);
           }
           using (var xrm = new XrmServiceContext(service))
           {
               for (int i = 0; i < userIdList.Length; i++)
               {
                   var users = xrm.SystemUserSet.Where(x => x.Id == new Guid(userIdList[i])).Select(n=>n).FirstOrDefault();
                   trace.Trace("User id and Name after Reterieve :" + users.Id + " ," + users.FullName);
                   var currentSystemUser = new EntityReference(SystemUser.EntityLogicalName , users.Id);
                   
                   trace.Trace("Current System User :" + currentSystemUser.Id);
 
 
                   GrantAccessRequest grantAccessRequest = new GrantAccessRequest()
                   {
                       Target = new EntityReference(sy_hrinformationupdate.EntityLogicalName),
                       PrincipalAccess = new PrincipalAccess
                       {
                           AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess,
                           Principal = currentSystemUser
                       }
                   };
 
                   trace.Trace("Principle access target:" + grantAccessRequest.PrincipalAccess.Principal.Id);
                   trace.Trace("Before Excute Grant Access Permission");
                   service.Execute(grantAccessRequest);
                   trace.Trace("After Excute Grant Access Permission");
 
               }
 
           }
       }
 
       [Input("UserIds")]
        public InArgument<string> UserIds { get; set; }
}


Error after Execution :-



Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: sy_hrinformationupdate With Id = 00000000-0000-0000-0000-000000000000 Does Not ExistDetail: 
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ActivityId>99b7e31a-3f50-4ad7-b05c-098483525728</ActivityId>
<ErrorCode>-2147220969</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>sy_hrinformationupdate With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist</Message>
<Timestamp>2018-05-29T08:15:36.8912489Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource>SdkClient</ExceptionSource>
<InnerFault>
<ActivityId>99b7e31a-3f50-4ad7-b05c-098483525728</ActivityId>
<ErrorCode>-2147220969</ErrorCode>
<ErrorDetails xmlns:d3p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>sy_hrinformationupdate With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist</Message>
<Timestamp>2018-05-29T08:15:36.8912489Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText i:nil="true" />
</InnerFault>
<OriginalException>System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: sy_hrinformationupdate With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)
at Microsoft.Crm.Extensibility.InprocessServiceProxy.ExecuteCore(OrganizationRequest request)
at Microsoft.Crm.Sandbox.SandboxSdkListener.ExecuteInternal(SandboxCallInfo callInfo, SandboxSdkContext requestContext, String operation, Byte[] serializedRequest, IExecutionContext context, String&amp; primaryEntityName)
at Microsoft.Crm.Sandbox.SandboxSdkListener.Execute(SandboxCallInfo callInfo, SandboxSdkContext requestContext, String operation, Byte[] serializedRequest) 
Original SdkErrors: 
</OriginalException>
<TraceText>Excution is just Started....
UserIds String :d9a508fd-d264-e611-80eb-5065f38ae9d1;cea508fd-d264-e611-80eb-5065f38ae9d1;
User Ids:d9a508fd-d264-e611-80eb-5065f38ae9d1
User Ids:cea508fd-d264-e611-80eb-5065f38ae9d1
User Ids:
User id and Name after Reterieve :d9a508fd-d264-e611-80eb-5065f38ae9d1 ,Test, Requester
Current System User :d9a508fd-d264-e611-80eb-5065f38ae9d1
Principle access target:d9a508fd-d264-e611-80eb-5065f38ae9d1
Before Excute Grant Access Permission</TraceText>
</OrganizationServiceFault>

I am unable find ,what is wrong with code


   



*This post is locked for comments

  • Verified answer
    Rawish Kumar Profile Picture
    13,758 on at
    RE: CRM Entity Records Sharing to User using c# Code , Entity(account) With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist .

    GrantAccessRequest grantAccessRequest = new GrantAccessRequest()

                      {

                          Target = new EntityReference(sy_hrinformationupdate.EntityLogicalName),

                          PrincipalAccess = new PrincipalAccess

    In your target you are passing a New Entity reference which obviously will not have any guid.

    you have paass the current entity id :

    something like below :

    IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

    Guid recordId= context.PrimaryEntityId;

    Target = new EntityReference(sy_hrinformationupdate.EntityLogicalName,

                                   recordId)

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans