Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Multiple system logs for the custom workflow activity

(0) ShareShare
ReportReport
Posted on by 568

Hi,

I have created a  custom workflow to updated related contacts for an account and everything works fine.The only issue that I am having is that in system logs I am able to get log for(WORKFLOW) once and  97 System Events that updates my field in the contacts.

I have been searching a long through this but I am unable to find this.

5488.logs.png

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;

namespace RelatedContact_CWA
{
    public class Class1 : CodeActivity
    {
        protected override void Execute(CodeActivityContext context)
        {
            ITracingService tracingservice = (ITracingService)context.GetExtension<ITracingService>();
            IWorkflowContext workflowcontext = context.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory servicefactory = context.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService _orgservice = servicefactory.CreateOrganizationService(workflowcontext.InitiatingUserId);

            try
            {

                Guid currentid = workflowcontext.PrimaryEntityId;

                QueryExpression query = new QueryExpression("account");
                query.Criteria = new FilterExpression();
                query.ColumnSet = new ColumnSet(true);
                var account = _orgservice.RetrieveMultiple(query);
                var accountres = _orgservice.RetrieveMultiple(query);

                foreach (var res in accountres.Entities)
                {
                    QueryExpression qe = new QueryExpression("contact");
                    qe.Criteria = new FilterExpression();
                    qe.ColumnSet = new ColumnSet(true);
                    qe.Criteria.AddCondition("parentcustomerid", ConditionOperator.Equal, currentid);
                    var contactres = _orgservice.RetrieveMultiple(qe);

                    if (contactres != null && contactres.Entities.Count > 0)
                    {
                        foreach (var subgridrecord in contactres.Entities)
                        {
                            var name = subgridrecord["fullname"].ToString();
                            Console.WriteLine(name);
                            subgridrecord["jobtitle"] = "developer";
                            _orgservice.Update(subgridrecord);
                            tracingservice.Trace("Update success");
                        }
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("error");
            }
        }
    }
}



Please advise on this.

Regards,
AxTechie2120

*This post is locked for comments

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

🌸 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…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the 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 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans