09.04.2014, 16:48 | #1 |
Участник
|
Workflow делает копию записи
Добрый день!
Ситуация такая, workflow делает копию записи, всё отлично, но нужно чтобы так же копировались survey questions которые там есть. Вот пока что вот такой код: Код: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Workflow; using System.Activities; namespace Bum.Survey.CRM.WorkflowActivity { public class CopySurvey : CodeActivity { [RequiredArgument] [Input("Survey status")] [AttributeTarget("bf_survey", "bf_survey_sts")] public InArgument<OptionSetValue> SurveyStatus { get; set; } [RequiredArgument] [Input("Name")] public InArgument<string> SurveyName { get; set; } [RequiredArgument] [Input("Startup")] public InArgument<DateTime> SurveyStartup { get; set; } [RequiredArgument] [Input("Finish")] public InArgument<DateTime> SurveyFinish { get; set; } [Input("Evaluating object")] [ReferenceTarget("bf_survey")] public InArgument<EntityReference> EvalObject { get; set; } protected override void Execute(CodeActivityContext activityContext) { IExecutionContext context = activityContext.GetExtension<IExecutionContext>(); IOrganizationServiceFactory serviceFactory = activityContext.GetExtension<IOrganizationServiceFactory>(); IOrganizationService _orgService = serviceFactory.CreateOrganizationService(context.UserId); ITracingService tracingService = activityContext.GetExtension<ITracingService>(); Entity survey = _orgService.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true)); survey.Id = Guid.Empty; survey.Attributes.Remove("bf_surveyid"); QueryExpression qry = new QueryExpression() { EntityName = "bf_surveyquestion", ColumnSet = new ColumnSet(true) }; qry.Criteria.AddCondition("bf_surveyquestion_survey", ConditionOperator.Equal, survey.Id); List<Entity> questions = _orgService.RetrieveMultiple(qry).Entities.ToList(); if (questions.Count >= 0) { } _orgService.Create(survey); } } } |
|
|
|