Steps
- Open your Notepad.
- Copy the code given below and paste it.
- Name it like spvalidation.js
- Add Content Editor Webpart in your page.
- Add saved.js file into your Webpart properties.
- <script>
- $(document).ready(function()
- {
-
- var checkFieldExist=checkFieldExists('Documents');
- });
-
- function checkFieldExists(listTitle){
-
- var context = new SP.ClientContext.get_current();
- var web = context.get_web();
- var list = web.get_lists().getByTitle(listTitle);
- var listFields = list.get_fields();
- context.load(listFields);
- context.executeQueryAsync(printFieldNames,onError);
-
- function printFieldNames() {
- var e = listFields.getEnumerator();
- var fieldExist = false;
- while (e.moveNext()) {
- var field = e.get_current();
- if (field.get_title() == "myfieldname") {
- fieldExist = true;
- }
- }
- return fieldExist;
- }
-
- function onError(sender,args)
- { return fieldExist;
- console.log(args.get_message());
- }
- }
- </script>
Conclusion
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.