1

I added a Web Part on new form page for a list, and added JavaScript code to it, which is working as expected for my SharePoint account. The same script is not working for any other user using the list that I created.

How to make the script to work for other users?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://site-name/Style%20Library/sputility.js"></script>
<script>
$(document).ready(function ()
{   
    var statusFld = SPUtility.GetSPField('Status');
    var status    = statusFld.GetValue();

    var node = document.querySelector('[title="Status"]');
    if(status  === "In Review") {
        if(node) {
           node.disabled = true;
        }
    }
});
</script>
  • Can you please add code you used to your question? Have you added code directly or referenced code file from somewhere else? Is you have used to file reference then make sure other users have permission on that file. – Ganesh Sanap Jan 22 at 6:00
  • @GaneshSanap Edited my question, added the script that I'm using. – user11158730 Jan 22 at 6:14
  • Can you please check if the other user has permission on "Style Library" as well as "sputility.js"? Are you getting any error in console? – Ganesh Sanap Jan 22 at 6:39
  • Please check the browser dev console for any errors. It will help to identify the issue. – Jefin Mathew Jan 22 at 7:15
0

Try using your code like below:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="https://site-name/Style%20Library/sputility.js"></script>
<script type="text/javascript">
    $(document).ready(function () {   
        var statusFld = SPUtility.GetSPField('Status');
        var status = statusFld.GetValue();

        var node = document.querySelector('[title^="Status"]'); //Using Starts with (^=) selector in JQuery benefits when your field is required.
        if(status === "In Review") {
            if(node) {
               node.disabled = true;
            }
        }
    });
</script>

Note:

  1. Make sure that other users have permission on the references JavaScript files from Style Library.
0

I just did "Check In" the jquery.min.js and sputility.js files. The problem was solved.

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.