2012-06-01 2 views
1

계정 엔티티에 연결된 수동으로 호출 된 프로세스가 있습니다. 이 프로세스에는 여러 단계가 있습니다. 첫 번째 단계 중 하나는 작업을 만들어 다른 사람에게 할당하는 것입니다. 이 사람이 메모를 추가하고 작업을 완료 할 것으로 예상됩니다.사례에서 사례로 메모 복사

프로세스를 추가하면 서비스 사례를 만드는 단계가 있습니다. 이 작업이 생성 된 후 위의 작업에서 새로 생성 된 서비스 사례로 메모를 복사하려고합니다.

나는이 작업을 시도하고 수행하기 위해 사용자 지정 워크 플로우 작업을 만들었습니다. 나는 그것을 배포하고 오류없이 프로세스 내에서 사용하고 서비스 사례의 메모 필드에 내용을 복사하지만 메모 내용이 아닌 작업의 제목을 복사합니다. 왜 있는지.

public class CopyNotes : CodeActivity 
{ 
    protected override void Execute(CodeActivityContext executionContext) 
    { 
     //Create the context 
     IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>(); 
     IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>(); 
     IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); 

     //get the notes associated with the source entity 
     Guid copyFromId = CopyFrom.Get(executionContext).Id; 
     Guid copyToId = CopyTo.Get(executionContext).Id; 

     EntityCollection copyFromNotes = RetrieveNotes(service, copyFromId); 

     if (copyFromNotes.Entities.Any()) 
     { 
      foreach (Entity e in copyFromNotes.Entities) 
      { 
       Entity newNote = new Entity("annotation"); 
       newNote.Attributes["subject"] = e.Attributes["subject"]; 
       newNote.Attributes["notetext"] = e.Attributes["notetext"]; 
       newNote.Attributes["objectid"] = new EntityReference() { Id = copyToId, LogicalName = CopyTo.Get(executionContext).LogicalName }; 
      } 
     } 
    } 

    private EntityCollection RetrieveNotes(IOrganizationService service, Guid relatedObject) 
    { 

     ConditionExpression condition = new ConditionExpression(); 
     condition.AttributeName = "objectid"; 
     condition.Operator = ConditionOperator.Equal; 
     condition.Values.Add(relatedObject.ToString()); 

     ColumnSet columns = new ColumnSet("subject", "notetext"); 

     QueryExpression query = new QueryExpression(); 
     query.ColumnSet = columns; 
     query.EntityName = "annotation"; 
     query.Criteria.AddCondition(condition); 

     EntityCollection results = service.RetrieveMultiple(query); 

     return results; 

    } 

    [RequiredArgument] 
    [ReferenceTarget("task")] 
    [Input("Copy notes from item")] 
    public InArgument<EntityReference> CopyFrom { get; set; } 

    [RequiredArgument] 
    [ReferenceTarget("incident")] 
    [Input("Copy notes to item")] 
    public InArgument<EntityReference> CopyTo { get; set; } 
} 

답변

3

실제로는 newNote를 정의한 후에 작성해야한다고 생각합니다.

foreach (Entity e in copyFromNotes.Entities) 
{ 
    Entity newNote = new Entity("annotation"); 
    newNote.Attributes["subject"] = e.Attributes["subject"]; 
    newNote.Attributes["notetext"] = e.Attributes["notetext"]; 
    newNote.Attributes["objectid"] = new EntityReference() { Id = copyToId, LogicalName = CopyTo.Get(executionContext).LogicalName }; 
    service.Create(newNote); 
} 

코드를 작성한 후에는 제목과 노트 텍스트가 모두 새 노트를 작성하는 데 효과적입니다.

+0

감사합니다. – sparkymark75

0

비동기 생성이 충분히 빠르면 표준 워크 플로에서이 작업을 수행 할 수 있습니다.

Andreas