Bhubaneswar, Odisha, India
+91-8328865778
support@softchief.com

Sample Custom Workflow Code Dynamics 365 CE or Dataverse

Sample Custom Workflow Code Dynamics 365 CE or Dataverse

Here is the Sample Custom Workflow Activities code for your usages. Modify the code as per your business need.

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System.Activities;

namespace ModernSchoolServerSideCode
{
    public class getoutstandingamount : CodeActivity
    {
        [Input("Student Record")]
        [ReferenceTarget("modern_student")]
        public InArgument<EntityReference> TargetStudent { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();

            // Use the context service to create an instance of IOrganizationService.             
            IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.InitiatingUserId);

            EntityReference currentStudentRecord = TargetStudent.Get(context);

            var fetchXML = @"<fetch version='1.0' mapping='logical' no-lock='false' distinct='true'>
                                <entity name='modern_studentpayment'>
                                    <attribute name='modern_studentpaymentid'/>
                                    <attribute name='modern_name'/>
                                    <attribute name='createdon'/>
                                    <attribute name='modern_fees'/>
                                    <filter type='and'>
                                        <condition attribute='statecode' operator='eq' value='0'/>
                                        <condition attribute='modern_student' operator='eq' value='{0}'  uitype='modern_student'/>
                                    </filter>
                                </entity>
                                </fetch>";
            fetchXML = string.Format(fetchXML, currentStudentRecord.Id);

            EntityCollection ec =  service.RetrieveMultiple(new FetchExpression(fetchXML));

            decimal totaloutstandingamiunt = 0;

            for (int i = 0; i < ec.Entities.Count; i++)
            {
                totaloutstandingamiunt = totaloutstandingamiunt + ((Money)ec.Entities[i].Attributes["modern_fees"]).Value;
            }

            OutAmount.Set(context, totaloutstandingamiunt);

        }

        [Output("OutstandingAmount")]
        public OutArgument<decimal> OutAmount { get; set; }
    }
}

Hope this helps.

You can enroll now !We are giving 30% discount on our Internship Program

Don’t miss the chance to participate in the upcoming Internship Program which will be done using Microsoft Dot Net Web Development Full Stack Technology. The new batch will be starting from May 20, 2024.  We will have most experienced trainers for you to successfully complete the internship with live project experience.

Why to choose Our Internship Program?

Industry-Relevant Projects
Tailored Assignments: We offer projects that align with your academic background and career aspirations.
Real-World Challenges: Tackle industry-specific problems and contribute to meaningful projects that make a difference.

Professional Mentorship
Guidance from Experts: Benefit from one-on-one mentorship from seasoned professionals in your field.
Career Development Workshops: Participate in workshops that focus on resume building, interview skills, and career planning.

Networking Opportunities
Connect with Industry Leaders: Build relationships with professionals and expand your professional network.
Peer Interaction: Collaborate with fellow interns and exchange ideas, fostering a supportive and collaborative environment.

Skill Enhancement
Hands-On Experience: Gain practical skills and learn new technologies through project-based learning.
Soft Skills Development: Enhance communication, teamwork, and problem-solving skills essential for career success.

Free Demo Class Available