I would like to refresh a Sitecore item after editing it programmatically.
Scenario: An Action of a workflow opens a dialog, does some operation and on clicking the OK button I want to refresh the Item on the Content Editor.
I tried the following approaches but they didn't work.
string load = string.Concat("item:load(id=", workflowItem.ID, ",language=", workflowItem.Language, ",version=", workflowItem.Version, ")");
Context.ClientPage.SendMessage(this, load);
string refresh = $"item:refreshchildren(id={workflowItem.ID})";
Context.ClientPage.ClientResponse.Timer(refresh, 12);
Your help is highly appreceiated.
Code Used for Custom Action:
public class ShowAuthenticationDialog
{
public void Process(WorkflowPipelineArgs args)
{
CreateContext(args);
}
private void CreateContext(WorkflowPipelineArgs args)
{
string controlUri = UIUtil.GetUri("control:AuthenticationDialog");
Item item = args.DataItem;
string nextStateId = args.CommandItem.Fields["Authentication Next State"]?.GetValue(true);
UrlString controlUrlString = new UrlString($"{controlUri}&ItemId={item.ID}&WorkflowNextStateId={nextStateId}");
SheerResponse.ShowModalDialog(controlUrlString.ToString());
string load = $"item:load(id={item.ID},language={item.Language},version={item.Version})";
Context.ClientPage.SendMessage(this, load);
}
}
Code for the OnOk method
protected override void OnOK(object sender, EventArgs args)
{
Assert.ArgumentNotNull(sender, "sender");
Assert.ArgumentNotNull(args, "args");
string itemId = WebUtil.GetQueryString("ItemId");
Database database = Factory.GetDatabase("master");
Item workflowItem = database.GetItem(itemId);
//TODO: Pass credentials to authentication service
if (true)
{
string newStateId = WebUtil.GetQueryString("WorkflowNextStateId");
string newState = database.GetItem(newStateId)?.DisplayName;
if (!string.IsNullOrWhiteSpace(newState))
{
ChangeWorkflowState(workflowItem, newState);
string load = $"item:load(id={workflowItem.ID},language={workflowItem.Language},version={workflowItem.Version})";
Context.ClientPage.SendMessage(this, load);
string refresh = $"item:refreshchildren(id={workflowItem.ID})";
Context.ClientPage.ClientResponse.Timer(refresh, 12);
//TODO: Add History
}
}
base.OnOK(sender, args);
}