SPRedirectWithID, copy and customize?

Aug 25, 2010 at 11:16 AM

I would like to use the SPRedirectWithID, however in this particular case I am not calling the function from a form or view of the list, so I am wondering if I can somehow override the listNameFromURL() function when it is called and provide the GUID for the list.  I see in the code that there is SPServices.defaults that looks like it allows overriding of some of the values (in my case I believe it would be 'listname'), but I'm unsure of how to go about using this function.  I tried the following, however when I try calling the SPServices.defaults I get the error "Function expected".

<script language="javascript" type="text/javascript">
 $(document).ready(function() {
  $().SPServices.defaults({
   listname: "{4d373746-a250-4ab2-9e24-85e16a80ef58}"
  });
  $().SPServices.SPRedirectWithID({ 
   redirectUrl: "EmpInfo.aspx"
  });
 });
</script>

Any help would be greatly appreciated.  Thanks!
Chanda


Aug 25, 2010 at 11:22 AM

Ok, well I see I didn't read the instructions for the SPServices.defaults function, so now I believe I have the syntax correct, however I'm not seeing the expected behavior of the SPRedirectWithID function (i.e. when I hit the page it is not updating the URL with the new source and last ID).  Here is what I have now:

<script language="javascript" type="text/javascript">
 $(document).ready(function() {
  $().SPServices.defaults.listname = "List Name";
  $().SPServices.SPRedirectWithID({ 
   redirectUrl: "EmpInfo.aspx"
  });
 });
</script>

Any ideas?

Thanks again, Chanda

Aug 25, 2010 at 11:53 AM

Well, I see now that what I want to do isn't going to work because I'm not working within form or view pages, so the system can't handle the parameter 'ID'.  So, what I'd like to do instead is to copy the SPRedirectWithID function and customize it by manually setting the name of the list and updating the parameter to be 'NewID'.  I've tried doing this but keep getting the error "SPServices is null or not an object".  What I attempted was to copy the entire SPRedirectWithID function and paste it at the bottom of jquery.SPServices-0.5.6.js just before the closing brackets.  I then renamed the function, updated the parameter to 'NewID' wherever 'ID' was used, and set var thisList = "List Name".  I updated my link to the .js file to change from the min version to the full version since that's where I added the new function and checked in all files, but I get the error as soon as the page loads.

I'm not sure where I'm going wrong, probably something simple, just stumped and don't know what to try now.

Thanks, Chanda

Coordinator
Aug 26, 2010 at 6:03 AM

Chanda:

If the page you're working with isn't a form, then why not just embed a hard link? I'm not sure what you're trying to do.

M.

Aug 29, 2010 at 12:52 AM

Thanks Marc,

After looking at it a bit more I did just that, hardcoded the link and it's working for the non-form pages.

Chanda