{"id":6105,"date":"2020-05-14T12:52:15","date_gmt":"2020-05-14T12:52:15","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=6105"},"modified":"2020-05-14T12:52:15","modified_gmt":"2020-05-14T12:52:15","slug":"create-multilevel-subtasks-in-a-task-list-using-csom","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/","title":{"rendered":"Create Multilevel Subtasks In a Task List using CSOM"},"content":{"rendered":"\n<p style=\"text-align:left\">              In this blog, we will see how to change the task list structure and make it into subtasks. Task list has a hidden field \u201cParentID\u201d which is of lookup type. We need to set <strong>lookupValueCollection<\/strong> using the root task item\u2019s ID value and assign its value to the &#8220;ParentID&#8221; field of the item that we are willing to add as a subtask.<\/p>\n\n\n\n<p>Through the\nbelow code, we will create subtasks in a task list using CSOM programmatically.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Security;\nusing Microsoft.SharePoint.Client;\n\nnamespace MultiLevelTaskList\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            ClientContext context = new ClientContext(\"https:\/\/domain \/sites\/demosite\");\n            string password = \"password\";\n            string user = \"user@domain.onmicrosoft.com\";\n            SecureString secureString = new SecureString();\n            foreach (char c in password.ToCharArray())\n            {\n                secureString.AppendChar(c);\n            }\n            SharePointOnlineCredentials cred = new SharePointOnlineCredentials(user, secureString);\n            context.Credentials = cred;\n            List list = context.Web.Lists.GetByTitle(\"TaskListWithSubtask\");\n            ListItem listItem = list.GetItemById(2);\n            context.Load(listItem);\n            context.ExecuteQuery();\n\n            var lookupValue = new FieldLookupValue();\n            lookupValue.LookupId = 1; \/\/ Get parent item ID and assign it value in lookupValue.LookupId\n\n            var lookupValueCollection = new FieldLookupValue[1];\n            lookupValueCollection.SetValue(lookupValue, 0);\n\n            listItem[\"ParentID\"] = lookupValueCollection; \/\/ set chidl item ParentID field\n\n            listItem.Update();\n            context.ExecuteQuery();\n          \n        }\n     }\n }<\/code><\/pre>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/05\/1-1-1024x430.png\" alt=\"\" class=\"wp-image-6106\"\/><\/figure>\n\n\n\n<p>The above\nimage shows the task list without having subtask.<\/p>\n\n\n\n<p>After the code\nexecutes, we can see the task list having a hierarchical structure. below\nImages shows task list having subtasks.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/05\/2-1024x537.png\" alt=\"\" class=\"wp-image-6107\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/05\/3-1024x503.png\" alt=\"\" class=\"wp-image-6108\"\/><\/figure>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Keywords: <\/span><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Task\nlist having hierarchical structures using CSOM<\/li><li>Task\nlist having subtasks using CSOM<\/li><li>Create\nSubtask in a task list using CSOM<\/li><li>Create\nMultilevel Subtask in a task list using CSOM<\/li><li>Arrange\ntask list into hierarchical structures using CSOM<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will see how to change the task list structure and make it into subtasks. Task list has a hidden field \u201cParentID\u201d which is of lookup type. We need to set lookupValueCollection using the root task item\u2019s ID value and assign its value to the &#8220;ParentID&#8221; field of the item that we are willing to add as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-6105","post","type-post","status-publish","format-standard","hentry","category-sharepoint"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Multilevel Subtasks In a Task List using CSOM - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Multilevel Subtasks In a Task List using CSOM - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"In this blog, we will see how to change the task list structure and make it into subtasks. Task list has a hidden field \u201cParentID\u201d which is of lookup type. We need to set lookupValueCollection using the root task item\u2019s ID value and assign its value to the &#8220;ParentID&#8221; field of the item that we are willing to add as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-14T12:52:15+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create Multilevel Subtasks In a Task List using CSOM - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/","og_locale":"en_US","og_type":"article","og_title":"Create Multilevel Subtasks In a Task List using CSOM - Softree Technology","og_description":"In this blog, we will see how to change the task list structure and make it into subtasks. Task list has a hidden field \u201cParentID\u201d which is of lookup type. We need to set lookupValueCollection using the root task item\u2019s ID value and assign its value to the &#8220;ParentID&#8221; field of the item that we are willing to add as [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/","og_site_name":"Softree Technology","article_published_time":"2020-05-14T12:52:15+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Create Multilevel Subtasks In a Task List using CSOM","datePublished":"2020-05-14T12:52:15+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/"},"wordCount":158,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/05\/1-1-1024x430.png","articleSection":["SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/","name":"Create Multilevel Subtasks In a Task List using CSOM - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/05\/1-1-1024x430.png","datePublished":"2020-05-14T12:52:15+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#primaryimage","url":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/05\/1-1-1024x430.png","contentUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/05\/1-1-1024x430.png"},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/create-multilevel-subtasks-in-a-task-list-using-csom\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Multilevel Subtasks In a Task List using CSOM"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=6105"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6105\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}