6

I am trying to setup a task list in SharePoint 2013 that will automatically add new tasks with start and end dates to the timeline.

Has anyone had any luck with this? I looked around at creating a workflow to do so, but could not find the features to do this.

Thanks for your help!

2

There are two options to derive at a solution. They are,

Using JavaScripts Using an Event Receiver

  1. Set required properties in the tasks list

In the RootFolder of a particular Tasks list, there are three properties relevant to the Timeline control. When we create the list, those properties are not automatically set. As a result we have to set those three properties, namely,

TimeLineDefaultView

TimeLineAllViews

TimeLine_TimeLine

- Get xml document in TimeLine_TimeLine property, and add required nodes

We have to add xml nodes to “tskSet” and “mlSet” sections to represent the task which is to be displayed in Timeline control.

here is code:

var web = properties.Web as SPWeb;
var doc = new XmlDocument();
var taskList = web.Lists[properties.ListId];
var root = taskList.RootFolder;

if (root.Properties["Timeline_Timeline"] == null)
{
 //Add timeline related properties
root.SetProperty("TimelineDefaultView", "Timeline");
root.SetProperty("TimelineAllViews", "Timeline");
 //Add default xml to Timeline_Timeline property
root.SetProperty("Timeline_Timeline",@"<TLViewData><fmtSet><fmt id='0' clr='FFEE2222' thm='0001' t1='0' t2='1' type='0' /><fmt id='1' clr='FFEE2222' thm='0001' t1='2' t2='3' type='1' /><fmt id='2' clr='FFEE2222' thm='0001' t1='4' t2='5' type='2' /><fmt id='3' clr='FFEE2222' thm='0001' t1='6' t2='7' type='3' /></fmtSet><fltSet><ft id='{00000000-0000-0000-0000-000000000000}' uid='4294967295' uidSrc='1' onTL='0' fmt='1' y='4294967282' x='0' h='20' /></fltSet><tskSet><t id='{00000000-0000-0000-0000-000000000000}' uid='4294967295' uidSrc='1' onTL='0' fmt='0' ch='4294967295' /></tskSet><options dateFormat='255' panZoomT='9' ProjSummFmt='3' showDates='1' showProjSummDates='0' showToday='1' showTS='1' timelineHeight='133' timelineWidth='-1' timescaleT='8' todayT='10' /><mlSet>
<m id='{00000000-0000-0000-0000-000000000000}' uid='4294967295' uidSrc='1' onTL='0' fmt='2' y='35' x='0' /></mlSet><txtSet><style id='0' type='0' clr='FFEE2222' thm='0001' sz='8' font='Segoe UI' bold='0' ital='0' und='0' strk='0' /><style id='1' type='1' clr='FFEE2222' thm='0001' sz='8' font='Segoe UI' bold='0' ital='0' und='0' strk='0' /><style id='2' type='2' clr='FF999999' thm='0001' sz='8' font='Segoe UI' bold='0' ital='0' und='0' strk='0' /><style id='3' type='3' clr='FFB3B3B3' thm='0001' sz='8' font='Segoe UI Light' bold='0' ital='0' und='0' strk='0' /><style id='4' type='4' clr='FF525051' thm='0001' sz='10' font='Segoe UI' bold='0' ital='0' und='0' strk='0' /><style id='5' type='5' clr='FFB3B3B3' thm='0001' sz='8' font='Segoe UI Light' bold='0' ital='0' und='0' strk='0' /><style id='6' type='6' clr='FF999999' thm='0001' sz='9' font='Segoe UI' bold='0' ital='0' und='0' strk='0' /><style id='7' type='7' clr='FF999999' thm='0001' sz='8' font='Segoe UI' bold='0' ital='0' und='0' strk='0' /><style id='8' type='8' clr='FF999999' thm='0001' sz='8' font='Segoe UI' bold='0' ital='0' und='0' strk='0' /><style id='9' type='9' clr='FFFFA614' thm='0001' sz='8' font='Segoe UI Semibold' bold='1' ital='0' und='0' strk='0' /><style id='10' type='10' clr='FFFFA72B' thm='0001' sz='10' font='Segoe UI Semibold' bold='0' ital='0' und='0' strk='0' /></txtSet></TLViewData>");
root.Update();
}

doc.LoadXml(root.Properties["Timeline_Timeline"].ToString());

//Create required xml nodes
var tElement = doc.CreateElement("t");
tElement.SetAttribute("id", "{" + properties.ListItemUniqueId.ToString() + "}");
tElement.SetAttribute("uid", properties.ListItemId.ToString());
tElement.SetAttribute("uidSrc", "1");
tElement.SetAttribute("onTL", "1");
tElement.SetAttribute("fmt", "0");
tElement.SetAttribute("ch", "4294967295");

var mElement = doc.CreateElement("m");
mElement.SetAttribute("id", "{" + properties.ListItemUniqueId.ToString() + "}");
mElement.SetAttribute("uid", properties.ListItemId.ToString());
mElement.SetAttribute("uidSrc", "1");
mElement.SetAttribute("onTL", "1");
mElement.SetAttribute("fmt", "2");
mElement.SetAttribute("y", "35");
mElement.SetAttribute("x", "0");

//Add created nodes to xml document
doc.SelectNodes("/TLViewData/tskSet/t")[doc.SelectNodes("/TLViewData/tskSet/t").Count - 1].AppendChild(tElement);
doc.SelectNodes("/TLViewData/mlSet/m")[doc.SelectNodes("/TLViewData/mlSet/m").Count - 1].AppendChild(mElement);
root.SetProperty("Timeline_Timeline", doc.OuterXml);
root.Update();

base.ItemAdded(properties);

http://dinushaonline.blogspot.com/2014/08/programmatically-add-tasks-to-timeline.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.