I have a XsltListViewWebPart with a custom link column used for change a value on current listitem using JavaScript.

image link

<a href="javascript:ApproveRejectRDA('{@ID}', true);" title="approve">

below javascript function...

function ApproveRejectRDA(id, approved) {
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('RDA');
    this.oListItem = oList.getItemById(id);

    if (approved == true)
       oListItem.set_item('NumStato', 16);
       oListItem.set_item('NumStato', 17);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

When I click on link, everything works properly only when the row is selected. If not, I get the following error:

Uncaught TypeError: Cannot read property 'get_current' of undefined

It seems that clientContext has no value.

Any ideas?


  • 3
    I do want to say this is a brilliant use of SharePoint! I love the ability to approve and reject straight from the listview!
    – Mike
    Commented Sep 29, 2014 at 15:36
  • Can you provide some more info about the SharePoint version and why you are using XSLT at all, instead of JSLink client-side JavaScript rendering templates. Thanks!
    – Sig Weber
    Commented Sep 29, 2014 at 20:04
  • I'm novice in SharePoint, and I don't know if this is a good solution. However, I'm working on SharePoint 2010. Any suggestion is wellcome! Thanks Commented Sep 30, 2014 at 8:00

2 Answers 2


It seems it occurs since sp.js library that contains SP.ClientContext class is not yet loaded when your code runs.

Use SP.SOD.executeFunc to ensure that the specified sp.js library is loaded when the code runs.

Try to change ApproveRejectRDA function to enclose it in SP.SOD.executeFunc like this:

function ApproveRejectRDA(id, approved) {
   SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
      var context = SP.ClientContext.get_current();
      //Your remaining code goes here...


You need to create a new object for clientContext. You have missed the word "new" while creating the context.

Just change the first statement as follows,

var clientContext = **new** SP.ClientContext.get_current();


  • Thanks, I already tried to create a new Object, but without success. It works only if the grid is focused (by clicking on any cell) Commented Sep 30, 2014 at 8:07

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.