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)

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
RichardM Profile Picture

RichardM 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans