gpt4 book ai didi

c# - Sitecore 工作流程批准/拒绝电子邮件

转载 作者:太空狗 更新时间:2023-10-29 21:10:36 25 4
gpt4 key购买 nike

我们正致力于在 Sitecore 6.2 网站的工作流程上实现一些自定义代码。我们的工作流程目前如下所示:

example sitecore workflow

我们的目标很简单:通过电子邮件向提交者发送电子邮件,告知其内容修订在“等待批准”步骤中是被批准还是被拒绝,并附上审阅者的评论。为此,我们在“批准”和“拒绝”步骤下添加了一个操作,如下所示:

sitecore workflow with actions

我们在尝试编写这段代码时遇到了两个大问题

  1. 似乎没有任何简单的方法来确定选择了哪个命令(解决方法是在操作步骤中传递一个参数,但我更愿意检测选择了哪个命令)
  2. 我似乎无法在此工作流程状态下获得评论(但我可以在下一个状态下获得它们)

有关更多上下文,这是我目前拥有的代码:

var contentItem = args.DataItem;
var contentDatabase = contentItem.Database;
var contentWorkflow = contentDatabase.WorkflowProvider.GetWorkflow(contentItem);
var contentHistory = contentWorkflow.GetHistory(contentItem);

//Get the workflow history so that we can email the last person in that chain.
if (contentHistory.Length > 0)
{
//contentWorkflow.GetCommands
var status = contentWorkflow.GetState(contentHistory[contentHistory.Length - 1].NewState);

//submitting user (string)
string lastUser = contentHistory[contentHistory.Length - 1].User;

//approve/reject comments
var message = contentHistory[contentHistory.Length - 1].Text;

//sitecore user (so we can get email address)
var submittingUser = sc.Security.Accounts.User.FromName(lastUser, false);
}

最佳答案

我最终得到了以下代码。我仍然看不出区分命令的好方法,而是实现了两个单独的类(一个用于批准,一个用于拒绝):

public void Process(WorkflowPipelineArgs args)
{
//all variables get initialized
string contentPath = args.DataItem.Paths.ContentPath;
var contentItem = args.DataItem;
var contentWorkflow = contentItem.Database.WorkflowProvider.GetWorkflow(contentItem);
var contentHistory = contentWorkflow.GetHistory(contentItem);
var status = "Approved";
var subject = "Item approved in workflow: ";
var message = "The above item was approved in workflow.";
var comments = args.Comments;

//Get the workflow history so that we can email the last person in that chain.
if (contentHistory.Length > 0)
{
//submitting user (string)
string lastUser = contentHistory[contentHistory.Length - 1].User;
var submittingUser = Sitecore.Security.Accounts.User.FromName(lastUser, false);

//send email however you like (we use postmark, for example)
//submittingUser.Profile.Email
}
}

关于c# - Sitecore 工作流程批准/拒绝电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6330806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com