protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } EntityReference noteToMove = NoteToMove.Get(context); if (noteToMove == null) { throw new ArgumentNullException("Note cannot be null"); } string recordUrl = RecordUrl.Get <string>(context); var dup = new DynamicUrlParser(recordUrl); string newEntityLogical = dup.GetEntityLogicalName(localContext.OrganizationService); Entity note = GetNote(localContext.OrganizationService, noteToMove.Id); if (note.GetAttributeValue <EntityReference>("objectid").Id == dup.Id && note.GetAttributeValue <EntityReference>("objectid").LogicalName == newEntityLogical) { WasNoteMoved.Set(context, false); return; } Entity updateNote = new Entity("annotation") { Id = noteToMove.Id, ["objectid"] = new EntityReference(newEntityLogical, dup.Id) }; localContext.OrganizationService.Update(updateNote); WasNoteMoved.Set(context, true); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { EntityReference noteToMove = NoteToMove.Get(executionContext); string recordUrl = RecordUrl.Get <string>(executionContext); var dup = new DynamicUrlParser(recordUrl); string newEntityLogical = dup.GetEntityLogicalName(service); Entity note = GetNote(service, noteToMove.Id); if (note.GetAttributeValue <EntityReference>("objectid").Id == dup.Id && note.GetAttributeValue <EntityReference>("objectid").LogicalName == newEntityLogical) { WasNoteMoved.Set(executionContext, false); return; } Entity updateNote = new Entity("annotation"); updateNote.Id = noteToMove.Id; updateNote["objectid"] = new EntityReference(newEntityLogical, dup.Id); service.Update(updateNote); WasNoteMoved.Set(executionContext, true); } catch (Exception e) { throw new InvalidPluginExecutionException(e.Message); } }