web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans