1

アカウントエンティティに関連付けられている手動で呼び出されたプロセスがあります。このプロセスにはいくつかのステップがあります。最初のステップの 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; }
}
4

2 に答える 2

3

newNote を定義した後、実際に 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);
}

これを行うと、コードが正常に機能し、タイトルとメモ テキストの両方を含む新しいメモが作成されました。

于 2012-06-02T05:56:46.857 に答える
0

非同期の作成が十分に速い場合は、標準のワークフローでこれを行うことができます。

アンドレアス

于 2012-06-06T11:20:10.130 に答える