This project has moved and is read-only. For the latest updates, please go here.

Can't Edit sharepoint page after adding JS thru CEWP

Jul 21, 2014 at 3:22 PM
I have exact scenario like the link below. I am trying to use auto complete (jquery, spservicec, etc.). It works but edit page does not seem to work.

I get following error with the developer tool.

SCRIPT5007: Unable to get property 'PageState' of undefined or null reference
sp.ribbon.js, line 2 character 79472

But I delete the reference to JS file from CEWP then I dont get the above error and able to edit the page where I dropped the cewp.
Jul 21, 2014 at 8:15 PM

Can you post your code?

Jul 22, 2014 at 3:47 PM
Edited Jul 22, 2014 at 9:25 PM
Here is the code.
<script type="text/javascript" src="/_layouts/jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/_layouts/jquery/jquery-ui-1.10.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="/_layouts/jquery/jquery.SPServices-2014.01.min.js"></script>
<link rel="stylesheet" type="text/css" href="/_layouts/jquery/jquery-ui-themes-1.10.4/themes/smoothness/jquery-ui.css"/>

<div class="ui-widget">
    <label for="EmployeeCode">Employee Code</label>
    <input type="text" size="100" id="EmployeeCode">    
    <input type="button" value="OK" id="btnSearch" name="btnSearch" />  

<script type="text/javascript">

function PostLoad() {
    // Hide Text Filter Control 
    var controlID = "ctl00_m_g_3c02ecf9_d389_42bf_ba2a_801aa56cf4af_SPTextSlicerValueTextControl";  
    var externalParties = [];
    window.onload = function() {
    window.setTimeout(readyCall, 1000);
        function readyCall(){
          var externalParties = [];
            operation: "GetListItems",
            listName: "Employees",
            CAMLViewFields: "<ViewFields> <FieldRef Name='EmployeeCode' /> <FieldRef Name='JobTitle' /> </ViewFields>",
            async: false,
            completefunc: function (xData, Status) {
              $(xData.responseXML).SPFilterNode("z:row").each(function() {
                externalParties.push($(this).attr("ows_EmployeeCode") + "  --  " +  $(this).attr("ows_JobTitle"));

                            source: externalParties,
                            minLength: 3
 <script type="text/JavaScript">
 function moveValue() {
   var EmployeeCodeField = document.getElementById("EmployeeCode");   
   var otherControl = document.getElementById("ctl00_m_g_3c02ecf9_d389_42bf_ba2a_801aa56cf4af_SPTextSlicerValueTextControl");
   //Making sure both fields are not undefined before accessing their properties.
   if(EmployeeCodeField && otherControl){
        var s = EmployeeCodeField.value;        
        s = s.substring(0, s.indexOf('--'));    
      otherControl.value = s.trim(); 
        __doPostBack('<%= btnSearch.UniqueID %>','')
Jul 23, 2014 at 9:41 AM
Edited Jul 24, 2014 at 3:32 AM

I'm not sure, but you may have a problem because you have two separate script blocks that need to know about each other. You probably should combine them into one. There also may be some timing issues with your code, as you are using several different methods to introduce lags into the process.

Jul 23, 2014 at 2:58 PM
I combined both JS into one and that seems to work. However I remove the following code then the code does not work at all meaning autopopulate does not happen after type in 3 characters into the text box.
window.onload = function() {
    window.setTimeout(readyCall, 1000);
Jul 24, 2014 at 3:35 AM
I don't think you need that timeout. What are you trying to wait for?

I also don't think that this is necessary:

Just put all of your script inside the $(document).read(). If it doesn't work, the try stepping through it in a debugger and see where the issue is.