SPServices is Undefied.

Jun 19, 2014 at 4:19 PM
I am facing strange issue while starting workflow from Javascript/Jquery using SPServices
Please find attached Screenshot for better understanding.
I have tried all the versions of SPServices(from 0.5.4 to 2014 ) and Jquery(from 1.7 to 1.11) with combinations.
but I am still not able to get it through
getting message from browser that SPServices is undefined.

Here is my code.



<script type ="text/javascript" src = "https://code.jquery.com/jquery-1.10.2.min.js"></script>
<!--script type ="text/javascript" src = "https://Server/sites/Test_Environment/Shared%20Documents/SPServices-0.5.4.min.js"></script--> <script type ="text/javascript" src = "https://Server/sites/Test_Environment/Shared%20Documents/jquery.SPServices.min.js"></script>


function StartWorkflow(ItemURL, ItemID)
{
alert(ItemURL);


$().SPServices({
    operation: "StartWorkflow",
    item: ItemURL,  
    templateId: "{8b65eb82-2890-486b-b63c-bee77c1c1779}",
    workflowParameters: "",
    async: true,
    completefunc: function () {
        SP.UI.Notify.addNotification("Workflow process started on selected item.", false);
    }

});
alert("Done");
}

Please find attached screenshot and suggest me the solution.
Image
Coordinator
Jun 19, 2014 at 4:22 PM
This simply means that your reference to the SPServices file is not correct and it's not loading in the page.

M.
Jun 20, 2014 at 9:41 AM
Hi Marc,

Thanks for reply, but I do added proper references
directly from my server, third party host, and so on.

but nothing has changed.

-Shri
Jun 20, 2014 at 11:20 AM
Even I have copied all the scripts from SPServices.js to allitems.aspx of list under script tag but error is still same.
Coordinator
Jun 20, 2014 at 2:10 PM
Edited Jun 20, 2014 at 2:11 PM
The error is telling you that SPServices isn't defined, so the reference can't be correct.

Take a look at the first page of the documentation at the bottom for some tips and tricks to figure this out.

M.
Jun 20, 2014 at 2:33 PM
Hi Marc,

SCRIPT438: Object doesn't support property or method 'SPServices'

This is the exact error I am getting on browser while running the script.

-Shri
Coordinator
Jun 20, 2014 at 5:36 PM
I understand that from the screenshot. That tells me that your reference to SPServices is incorrect.

M.
Jun 21, 2014 at 12:15 AM
Another case where I have seen this happen is when multiple versions jQuery are being loaded. It's possible that SPServices "attaches" itself to the instance you don't have a reference to.

Are you sure one one jQuery file is included in the page?


--
Paul T.

-- Sent from Mobile

Marked as answer by ShripadKulkarni on 6/23/2014 at 5:26 AM
Jun 23, 2014 at 11:01 AM
Hi Paul,

Thanks for reply,

yes there was only one JQuery ref, also when tried without jquery ref, it shows me the error "SCRIPT5009: 'jQuery' is undefined
SPServices-0.5.4.min.js, line 19 character 2
SCRIPT5009: 'jQuery' is undefined
SPServices-0.5.4.min.js, line 19 character 2
"

-Shri
Jun 23, 2014 at 11:57 AM
Sounds like its time for real debugging. You will need to recheck how the script files are being loaded and in what order. Then kick up the developers tools and start stepping throught code.


--
Paul T.

-- Sent from Mobile

Jun 23, 2014 at 1:26 PM
Hi Paul,

This problem has been resolved !!!,
there was a problem in Master Page, Master page was having the ref of jquery as well as this page also was.
Great Help.. Thanks a ton.

but for now there was no error, but workflow is not running,

Please find details below
Workflow type : Designer workflow.
Function : Creating new Item from existing item.
Parameters : no parameters.
Env : office 365 ( SP 2013 online )

Code ;



function StartWorkflow(ItemURL, ItemID)
{
//alert(ItemURL);

$().SPServices({
    operation: "StartWorkflow",
    item: ItemURL,  
    templateId: "{8b65eb82-2890-486b-b63c-bee77c1c1779}",
    workflowParameters: "<root />",
    async: true,
    completefunc: function() {
    alert("Copied");

    }

});
}

Could you please suggest me if anything is wrong in this code.

Thanks

-Shri
Jun 23, 2014 at 1:55 PM
Ahh.. So it was a duplicate version of jQuery being loaded... this problem seems to come allot now a days - I think primary because admins are including it in the Master page by default (due to its uselfulness) and advanced users are not normally looking for it... they are just "copy and pasting" code from blogs or forums... There are (at lest) 3 issues that can cause this problem:

  1. (as Marc indicated) incorrect reference to the jQUery library
  2. Multiple version of jQuery being loaded (SPServices **could** get attached to the jQuery version your code does not have a reference to)
  3. SPServices loaded prior to jQuery library (out of order script loading)

Re: your "real issue"
I would open up a new thread, since it not related to your original problem... I have seen posts here on how to start workflows that go into very good detail on how to do it and what to watch out for... Just search for it.


_________
Paul T


Jun 23, 2014 at 2:56 PM
Hi Paul,

Another problem is also resolved, no need to Open new thread, there was problem with my out parameter.

Thanks Paul, Marc.


-Shri
Sep 23, 2014 at 8:32 PM
Edited Sep 23, 2014 at 8:33 PM
Hello,

I'm new here so forgive me if I am writing in a bad topic. I would like to ask about StartWorfklow (using SPServices) for multiple selected FILES in library.
I tried to do that using this example: http://sympmarc.com/2013/01/21/spservices-stories-1-how-to-start-a-workflow-on-multiple-items-in-a-list/ but without success.

I think it's the problem with ItemUrl. Which ItemUrl should I use to method StartWorkflow when I try to use it for file in library?

Thank you very much for any help.

Regards,
Wojtek
Coordinator
Sep 23, 2014 at 8:51 PM
Wojtek:

The itemUrl should be the full file path to the document, e.g., http://servername/sitename/libraryname/filename.

M.