0

Embedding javascript into a Calculated column works well, such as in this case

Using HTML to recalculate calculated column

However, where the following code

="function setTaskID(TR){"
&"  var CTX=new SP.ClientContext.get_current();"
&"  var list=CTX.get_web().get_lists().getById(   SP.ListOperation.Selection.getSelectedList());"
&"  var ID=TR.id.split(String.fromCharCode(44))[1];"
.
.
.   

is initiated automatically by a timeout

IF(INT(TaskID),"","<img  src=""/_layouts/images/blank.gif""  onload=""{"
&setTaskIDfunction
&"var TR=this.parentNode.parentNode.parentNode;"
&"setTimeout(setTaskID(TR),1000);"

AND

a CEWP has been added to the page containing CSS

   <style type="text/css">
   </style>

Then the function SP.ClientContext.get_current fails with

 Unable to get property 'get_current' of undefined or null reference

I have used the following code in the CEWP as well

  <style type="text/css">
  </style>
  <script src="https://oursites.../jquery.SPServices-2014.02.js"></script>

and this won't work either.

Remove the CEWP and the code works fine.

What can I add to the CEWP to overcome the error?

3
  • Since you are now using SPServices (when you started on this adventure you said No external script files allowed) I now say do not stuff Javacript in Calculated Columns but use a separate JSfile with code. Just a CEWP alone does not break the code, you must have a scrpting error someplace else Commented Jan 29, 2016 at 9:07
  • Self-education has really helped! However, there is still a lot locked down (SPDesigner etc), I was thinking along the same lines as you have suggested.
    – southskies
    Commented Feb 1, 2016 at 0:03
  • Created a new list, with no javascript, no CEWP, one simple text column. This list is failing, so something is fundamentally wrong. I'm getting messages "Unable to get property 'PageManager' of undefined or null reference" on display of the list. if I continue, the message becomes "Unable to get property 'MenuTitle' of undefined or null reference"
    – southskies
    Commented Feb 1, 2016 at 5:33

1 Answer 1

0

The error appears to relate to the problem that I posted here

Unable to get property 'PageManager' of undefined or null reference SP2013

I have now fixed that error, so I'm assuming that this problem will be fixed as well.

It makes sense to move the code out of the Calculated column into the JS, so this is what I am going with, and the solution works well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.