Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Multiple system logs for the custom workflow activity

Posted on by 560

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans