4

So i have added content editor webpart in NewForm.aspx and reading the code to javascript file called HideFields.ps1. SO the script as below:

HideFields.ps1

 <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" language="javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
    <script type="text/javascript">

    $(document).ready(function() {

     $().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
      var xml = xData.responseXML.xml;

       //If the current User does belong to the group "Test Group"
        if (xml.search('Test Group') == -1)
         {
             $('td.ms-formlabel:contains("Description")').parent().hide();

           }  
        }

     });

    });
    </script>

The above script work as expected if i reference jquery library and SPService library externally.

What it does not work if i have save the file in the same location of this javascript file (HideFields.ps1).

<script type="text/javascript" language="javascript" src="~siteCollection/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>

I tried also this one since the all the files existed in the same location

<script type="text/javascript" language="javascript" src="jquery.SPServices-0.7.1a.min.js"></script>
Supermode
  • 1,799
  • 2
  • 16
  • 33

2 Answers2

3

If site url like http://sp, reference the library as:

<script type="text/javascript" language="javascript" src="/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>

If site url like http://sp/sites/team, reference the library as:

<script type="text/javascript" language="javascript" src="/sites/team/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>

Update:

My test result:

enter image description here enter image description here

Lee
  • 4,271
  • 1
  • 7
  • 7
0

Try these 2 options -

  • Place your files in some other custom libraries other than "Site Assets" or "Style Library", and then refer it in your HTML from there.
  • Put your site in trusted locations in Internet Options settings of IE (Settings > Internet Options > Security > Trusted Sites > Sites > Add your site
Satyajit Paul
  • 568
  • 2
  • 13