{"id":667,"date":"2017-02-09T07:06:11","date_gmt":"2017-02-09T07:06:11","guid":{"rendered":"http:\/\/blog.softreeconsulting.com\/?p=667"},"modified":"2017-02-09T07:06:11","modified_gmt":"2017-02-09T07:06:11","slug":"create-custom-list-view-using-jscom","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/","title":{"rendered":"Create Custom List View using JSCOM"},"content":{"rendered":"<p>This below-mentioned code block will create the custom list view in a specific list. You can also set your custom view fields while creating the list view.<\/p>\n<p>[code lang=&#8221;c&#8221;]<\/p>\n<p>var oContext = SP.ClientContext.get_current();<br \/>\nvar oWeb = oContext.get_web();<br \/>\nvar oList = oWeb.get_lists().getByTitle(&#8220;MyList&#8221;); \/\/Enter title of your list<br \/>\nhostContext.load(oList);<br \/>\nhostContext.executeQueryAsync(CreateListView(oContext, oList),<br \/>\nfunction (sender, args) {<br \/>\n\/\/On Error<br \/>\nconsole.log(args.get_message());<br \/>\n});<br \/>\nfunction CreateListView(oContext, oList) {<\/p>\n<p>var viewFieldColl = [&#8216;Column1&#8217;, &#8216;Column2&#8217;, &#8216;Column3&#8217;]; \/\/Add your list fields title that you want to add in the new view<\/p>\n<p>var listViewColl = oList.get_views();<\/p>\n<p>var myView = new SP.ViewCreationInformation();<br \/>\nmyView.set_title(&#8220;MyNewView&#8221;); \/\/Enter a title for your new view<br \/>\nmyView.set_viewFields(viewFieldColl);<br \/>\nvar camlQuery = new SP.CamlQuery();<br \/>\nvar query = &#8220;&lt;View&gt;&lt;RowLimit&gt;100&lt;\/RowLimit&gt;&lt;\/View&gt;&#8221;; \/\/You can modify view query as per your requirement<br \/>\ncamlQuery.set_viewXml(query);<br \/>\nmyView.set_query(camlQuery);<br \/>\nmyView.set_viewTypeKind(2048); \/\/View type kind 2048 represents datasheet view<\/p>\n<p>myView.set_setAsDefaultView(true); \/\/If you want to set your new view as default view<br \/>\nlistViewColl.add(myView);<br \/>\nappContext.load(listViewColl);<br \/>\nappContext.executeQueryAsync(function () {<br \/>\nconsole.log(&#8220;Succesfully created list view.&#8221;);<br \/>\n}, function (sender, args) {<br \/>\n\/\/On Error<br \/>\nconsole.log(args.get_message());<br \/>\n});<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n<p>This solution is brought to you by our SharePoint professionals&#8230;<\/p>\n<p><a href=\"http:\/\/softreeconsulting.com\">Softree Consulting<\/a> employs SharePoint consultants, We are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants have the right bent of mind to understand and execute customer requirements. Be it web part development, migrating from SharePoint 2010\/2013 to SharePoint 2013\/2016, Office 365 or something else in SharePoint, we strive to deliver the best<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This below-mentioned code block will create the custom list view in a specific list. You can also set your custom view fields while creating the list view. [code lang=&#8221;c&#8221;] var oContext = SP.ClientContext.get_current(); var oWeb = oContext.get_web(); var oList = oWeb.get_lists().getByTitle(&#8220;MyList&#8221;); \/\/Enter title of your list hostContext.load(oList); hostContext.executeQueryAsync(CreateListView(oContext, oList), function (sender, args) { \/\/On Error console.log(args.get_message()); }); function CreateListView(oContext, oList) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127],"tags":[],"class_list":["post-667","post","type-post","status-publish","format-standard","hentry","category-office-365"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Custom List View using JSCOM - 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\/office-365\/create-custom-list-view-using-jscom\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Custom List View using JSCOM - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"This below-mentioned code block will create the custom list view in a specific list. You can also set your custom view fields while creating the list view. [code lang=&#8221;c&#8221;] var oContext = SP.ClientContext.get_current(); var oWeb = oContext.get_web(); var oList = oWeb.get_lists().getByTitle(&#8220;MyList&#8221;); \/\/Enter title of your list hostContext.load(oList); hostContext.executeQueryAsync(CreateListView(oContext, oList), function (sender, args) { \/\/On Error console.log(args.get_message()); }); function CreateListView(oContext, oList) [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-09T07:06:11+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 Custom List View using JSCOM - 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\/office-365\/create-custom-list-view-using-jscom\/","og_locale":"en_US","og_type":"article","og_title":"Create Custom List View using JSCOM - Softree Technology","og_description":"This below-mentioned code block will create the custom list view in a specific list. You can also set your custom view fields while creating the list view. [code lang=&#8221;c&#8221;] var oContext = SP.ClientContext.get_current(); var oWeb = oContext.get_web(); var oList = oWeb.get_lists().getByTitle(&#8220;MyList&#8221;); \/\/Enter title of your list hostContext.load(oList); hostContext.executeQueryAsync(CreateListView(oContext, oList), function (sender, args) { \/\/On Error console.log(args.get_message()); }); function CreateListView(oContext, oList) [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/","og_site_name":"Softree Technology","article_published_time":"2017-02-09T07:06:11+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\/office-365\/create-custom-list-view-using-jscom\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Create Custom List View using JSCOM","datePublished":"2017-02-09T07:06:11+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/"},"wordCount":287,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"articleSection":["Office 365"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/","url":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/","name":"Create Custom List View using JSCOM - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"datePublished":"2017-02-09T07:06:11+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/office-365\/create-custom-list-view-using-jscom\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Custom List View using JSCOM"}]},{"@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\/667","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=667"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/667\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}