Steps
- Open your Notepad.
- Copy the code given below and paste it.
- Name it spvalidation.js.
- Add Content Editor Webpart in your page.
- Add saved.js file into your Webpart properties.
- <script>
- $(document).ready(function()
- {
-
- ChecListalreadyexists('Documents');
- });
- function ChecListalreadyexists(listTitle)
- {
- var context = SP.ClientContext.get_current();
- var web = context.get_web();
- var site = context.get_site();
- var rootWeb = site.get_rootWeb();
- var subWebs = rootWeb.get_webs();
-
- context.load(subWebs, 'Include(Title,Lists)');
- context.executeQueryAsync(
- function () {
- for (var i = 0; i < subWebs.get_count(); i++) {
- var subWeb = subWebs.itemAt(i);
- var lists = subWeb.get_lists();
- if(get_listExists(lists,listTitle)) {
- console.log(subWeb.get_title());
- }
- }
- },
- function (sender, args) {
- console.log(args.get_message());
- }
- );
- }
-
-
-
- function get_listExists(lists,listTitle)
- {
- var listExists = false;
- var le = lists.getEnumerator();
- while (le.moveNext()) {
- var list = le.get_current();
- if(list.get_title() == listTitle) {
- listExists = true;
- break;
- }
- }
- return listExists;
- }
-
- </script>
Was my blog helpful? If yes, please let me know; and if not, please explain what was confusing or missing.
I’ll use your feedback to double-check the facts, add info and update this blog.