$().SPServices.SPLookupAddNew

Mar 25, 2010 at 6:59 PM
Edited Mar 25, 2010 at 7:00 PM

Great work!!!!

However, I'm sorry, I am really confused now. I have downloaded the necessary files but am really confused as to where to put the actual script. This is what I've done so far:

1) In Default.Master, I referenced the files and added the script as follows:
*************************************************************************************************
<script language="javascript" type="text/javascript" src="/_layouts/eb/jquery-1.4.2.js"></script>
<script language="javascript" type="text/javascript" src="/_layouts/eb/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$().SPServices.SPLookupAddNew({
lookupColumn: "Category",
promptText: "Add new {0}",
completefunc: null,
debug: true
});
</script>
*************************************************************************************************

2) I have a list called "Test" with a lookup field "Category" to a list called "Category".
3) Go to Test list, add new item, no fancy "Add New Category" hyperlink.
4) I put the entire code in the Test's NewForm.aspx page too, still nothing.

I've even added the whole code into a CEWP right on the list page and still nothing.

Obviously I am doing something wrong. Could you please point out the error of my ways?

Perhaps it's the $(document)? Maybe it should be $(list) or $()??

Thanks

Carl

Coordinator
Mar 25, 2010 at 7:39 PM

Carl:

The most likely issue is that your references to the two jQuery libraries aren't valid.  A few things:

  • NEVER edit default.master.  You never know when you might need to go back to it or reference it as it came out of the box. Always take a copy and edit that.
  • The script should go into the form page(s) anyway, not the master page.  (You can add the references to the libraries in the master page if you are going to use them pervasively, but there's some overhead to download them on every page.)
  • You're missing the closing }); for the (document).ready. (Indenting your code is always a good idea so that you can spot these missing bits.)
  • Add an alert like I show below; if the alert fires, then the jQuery library is referenced correctly. If it doesn't fire, you've got bad references.
  • I note that you have installed the libraries in _layouts.  There are different schools of thought on this, but I always recommend installing them in a Document Library at the root of the Site Collection for easier management.  I believe that if you can avoid touching the server, you should.
<script language="javascript" type="text/javascript" src="/_layouts/eb/jquery-1.4.2.js"></script>
<script language="javascript" type="text/javascript" src="/_layouts/eb/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
alert("jQuery is working!"); $().SPServices.SPLookupAddNew({ lookupColumn: "Category", promptText: "Add new {0}", completefunc: null, debug: true }); }); </script>

M.

Mar 25, 2010 at 8:58 PM
Edited Mar 26, 2010 at 6:20 PM
Hi sympmarc thanks for getting back to me so quick, much appreciated, I'm really trying to make this work, so far I've 
been at it the whole day (no laughing). I added the following directly to the top of the NewForm.aspx 
page (just under the <%@ Page language="C#" .....) for the Test list and added the files to a jQueryLibray library.

<asp:Content ContentPlaceHolderID="AddNewItem" runat="server">
<script language="javascript" type="text/javascript" src="/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    alert("jQuery is working!");
    $().SPServices.SPLookupAddNew({ 
      lookupColumn: "Category",
      promptText: "Add new {0}",
      completefunc: null,
      debug: true
    });
  });
</script>
</asp:Content>

I proceed to Add New Item and receive the error:           An unexpected error has occurred.
I'm not usually this thick and don't get why it's not working.
Carl
Coordinator
Mar 25, 2010 at 9:01 PM

This is probably one of those cases where reading the documentation would have been helpful. (i'm being serious, not sarcastic.)  Take a look at the bottom of this page:
http://spservices.codeplex.com/documentation

M.

Mar 26, 2010 at 7:44 PM
Edited Mar 26, 2010 at 7:58 PM

Hey Marc. Nope, still no go, but yes knew about that but since I was already using the modified NewForm.aspx I didn't think I needed to re-point to it.

Therefore, I went your route and create a NewFormCustom.aspx page, and added the following script to top of the page, and pointed to the NewFormCustom.aspx page:

<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/dev/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/dev/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    alert("jQuery is working!");
    $().SPServices.SPLookupAddNew({ 
      lookupColumn: "MyLookup",
      promptText: "Add new {0}",
      completefunc: null,
      debug: true
    });
  });
</script>
</asp:Content>

Still "An unexpected error has occurred." I went back to the list properties/Supporting Files and found the content type still on Folder. No matter what I've done, 
nothing will stick except Folder. Even though I create extra content types, have Folder show on New. Still won't take. 


Do you think that's the only issue preventing this from working? I've tried on two physically and completely different servers and same error.

I even double-checked the technique using your post;
A jQuery Library for SharePoint Web Services (WSS 3.0 and MOSS): Real World Example – Part 1
Cheers
Carl
Coordinator
Mar 26, 2010 at 7:55 PM

Carl:

The fact that Folder is showing is fine. The list is just alphabetical. The important thing is to pick the non-Folder Content Type (Item?) and set the NewForm for that.

M.

Mar 26, 2010 at 8:03 PM

Roger, didn't realize it functions similar to parent-child relationship.

To speed things up I'm trying using a CEWP on the list page for now. The alert automatically pops up "jQuery is working!", Then the window pops up displaying

Error in Function
SPServices.SPLookupAddNew

Parameter
lookupColumn: MyLookup

Message
Column not found on page.

The column is present, I know that. At least it's a little closer.

Carl

Coordinator
Mar 26, 2010 at 8:07 PM

It need to be the DisplayName of the column, not the StaticName.  So, for instance, if the column is called "My Lookup", the StaticName is "My_x0020_Lookup" and the DsiplayName is "My Lookup".

M.

Mar 26, 2010 at 8:30 PM
Edited Mar 26, 2010 at 8:30 PM

Yes Siree.

I named it MyLookup to avoid any naming issues during testing. God knows I'm having my share.

I'm also very interested in checkingout that very nifty rearrangment of radio buttons!!

Carl

 

Coordinator
Mar 27, 2010 at 12:34 AM

So was that a success or are you still stuck?

M.

Mar 27, 2010 at 1:52 AM

Er um... sorry, don't freak but still stuck. I was just mentioning the name to let you know that it's definitely not a naming problem. Still same debug error message. I'm completely stymied!! The only difference is when I added the script to the CEWP I immediately receive the success alert but then it gives me the error as described above.

I've done everything (AFAIK) you mentioned, on two separate servers. The only thing I haven't tried is referencing the non-minified libraries,  

CW

Coordinator
Mar 27, 2010 at 3:53 AM

*I'm* not going to freak out, Carl!  Just trying to make sure that things work for you.

The minification shouldn't be the problem.  Can you send me a screenshot of the form? marc dotto anderson atta sympraxisconsulting dotta com

M.

Coordinator
Mar 28, 2010 at 1:47 AM

Carl:

From what you sent me in email, I think I see the problem.  You've added a new ContentPlaceHolder called AddNewItem instead of putting the script inside

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

The extra ContentPlaceHolder is undoubtedly what is causing the error.  Sorry I didn't catch that when you posted it above.

SharePoint *is* loading the correct form (EditFormCustom.aspx) as you can see in the URL when you get the error.

You should use relative addressing for the script src in all cases. (Relative links are always preferable.)  This keeps you "safe" in case the servername changes, DNS issues, etc.

<script language="javascript" type="text/javascript" src="/sites/dev/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/sites/dev/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script

M.

Mar 28, 2010 at 3:13 AM
Did you hear my yeeeehawww??
Thanks very much for that. That was just my lack of knowledge on those type of things. Thanks for the relative link tip. I agree 1000%. I just provided absolute since once I take this off Dev, I'll give realtive but do appreciate the heads up. You can never hear correct methods enough.
I so badly needed this type of functionality (that should've been available OOTB anyway). I can't wait to try the other scrpts especially that very cool related info script!!
BTW, great work you're doing there, it's not overlooked, trust me. I'll make sure I add you to our enforcement site as a source/resource/consultant.
Cheers (for real this time)
Carl


From: sympmarc [mailto:notifications@codeplex.com]
Sent: March 27, 2010 8:48 PM
To: Williams,Carl [Ontario]
Subject: Re: $().SPServices.SPLookupAddNew [SPServices:207320]

From: sympmarc

Carl:

From what you sent me in email, I think I see the problem. You've added a new ContentPlaceHolder called AddNewItem instead of putting the script inside

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

The extra ContentPlaceHolder is undoubtedly what is causing the error. Sorry I didn't catch that when you posted it above.

SharePoint *is* loading the correct form (EditFormCustom.aspx) as you can see in the URL when you get the error.

You should use relative addressing for the script src in all cases. (Relative links are always preferable.) This keeps you "safe" in case the servername changes, DNS issues, etc.

<script language="javascript" type="text/javascript" src="/sites/dev/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/sites/dev/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script

M.

Coordinator
Mar 28, 2010 at 4:05 AM

Great! Glad you got it sorted out.  Let me know if I can be of any further help.

M.

Mar 29, 2010 at 1:22 AM
Roger. Great utilities!!
Carl


From: sympmarc [mailto:notifications@codeplex.com]
Sent: March 27, 2010 11:06 PM
To: Williams,Carl [Ontario]
Subject: Re: $().SPServices.SPLookupAddNew [SPServices:207320]

From: sympmarc

Great! Glad you got it sorted out. Let me know if I can be of any further help.

M.

Mar 29, 2010 at 2:18 AM
Edited Mar 29, 2010 at 2:24 AM
Actually I do have one thing. I did get the radio button arranger working ok. Now I'm adding your SPDisplayRelatedInfo script,.
 
I've added a lookup field "District" to the Test List. The lookup list is called Regional District, the column name is Title and the two other fields to show up "Region" and "Id".
 
Here is the entire script set I have so far. The first two work ok, Related info doesn't.
 
<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $().SPServices.SPLookupAddNew({ 
      lookupColumn: "Region",
      promptText: "Add New {0}",
      completefunc: null,
      debug: true
    });
  });
</script>
<script type="text/javascript">
 $(document).ready(function() {
    $().SPServices.SPArrangeChoices({
     columnName: "Choices",
     perRow: 4
    });
});
</script>
<script type="text/javascript">
 $(document).ready(function() {
 alert("jQuery SPDisplayRelatedInfo is working!");
   $().SPServices.SPDisplayRelatedInfo({
     columnName: "District",
     relatedList: "Regional District",
     relatedListColumn: "Title",
     relatedColumns: ["Region", "Id"],
     displayFormat: "list"
     });
 });
</script>
Thanks again
Carl
Coordinator
Mar 29, 2010 at 2:22 AM

There's always more. ;+)  Looks like your paste in didn't work.  Try again?

M.

Mar 29, 2010 at 2:25 AM

Really eh :)

I edited the comment, you should be able to see now.

CW

Coordinator
Mar 29, 2010 at 2:30 AM

Ok, you don't want to have separate script blocks; you should have one $(document).ready. Also, you can "turn on" debug mode for SPDisplayRelatedInfo, too.

M.

<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $().SPServices.SPLookupAddNew({ 
      lookupColumn: "Region",
      promptText: "Add New {0}",
      completefunc: null,
      debug: true
    });
    $().SPServices.SPArrangeChoices({
     columnName: "Choices",
     perRow: 4
    });
   $().SPServices.SPDisplayRelatedInfo({
     columnName: "District",
     relatedList: "Regional District",
     relatedListColumn: "Title",
     relatedColumns: ["Region", "Id"],
     displayFormat: "list",
     debug: true
}); }); </script>
Mar 29, 2010 at 2:33 AM

Roger. I'm on it.

CW

Mar 29, 2010 at 2:52 AM

Oh brother. I did what you said and broke something, now non of them work.

<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
       $().SPServices.SPLookupAddNew({ 
         lookupColumn: "Region",
         promptText: "Add New {0}",
         completefunc: null,
         debug: true
       });
       $().SPServices.SPArrangeChoices({
	     columnName: "Choices",
	     perRow: 4
       });
         alert("jQuery SPDisplayRelatedInfo is working!");
       $().SPServices.SPDisplayRelatedInfo({
	     columnName: "District",
	     relatedList: "Regional District",
	     relatedListColumn: "Title",
	     relatedColumns: ["Region", "Id"],
	     displayFormat: "list"
	     debug: true
       });
  });
</script>

CW
Coordinator
Mar 29, 2010 at 2:55 AM

Sorry, my bad. You need a comma:

displayFormat: "list",
debug: true

Mar 29, 2010 at 2:58 AM
Your bad? No, there is a comma.


From: sympmarc [mailto:notifications@codeplex.com]
Sent: March 28, 2010 9:55 PM
To: Williams,Carl [Ontario]
Subject: Re: $().SPServices.SPLookupAddNew [SPServices:207320]

From: sympmarc

Sorry, my bad. You need a comma:

displayFormat: "list",
debug: true

Mar 29, 2010 at 3:43 AM
We've got related fields!! Great!
Seems like you can only have one jQuery per field though. I set up a relatedfield with the Region field that has the addnew function but only shows the title of the related field then throws the Column not found in related list error. Not a hill to die on, I was just seeing if it'd work.
Cheers and Thanks Again Marc
Carl


From: sympmarc [mailto:notifications@codeplex.com]
Sent: March 28, 2010 9:55 PM
To: Williams,Carl [Ontario]
Subject: Re: $().SPServices.SPLookupAddNew [SPServices:207320]

From: sympmarc

Sorry, my bad. You need a comma:

displayFormat: "list",
debug: true

Coordinator
Mar 29, 2010 at 3:47 AM

They should be able to coexist. If not, I may have a bug.

M.

Mar 29, 2010 at 2:18 PM

Yes, sometimes the column heading of the extra related fields would show up, but no data. Antibiotics maybe?

From: sympmarc [mailto:notifications@codeplex.com]
Sent: March 28, 2010 10:47 PM
To: Williams,Carl [Ontario]
Subject: Re: $().SPServices.SPLookupAddNew [SPServices:207320]

From: sympmarc

They should be able to coexist. If not, I may have a bug.

M.

Read the full discussion online.

To add a post to this discussion, reply to this email (SPServices@discussions.codeplex.com)

To start a new discussion for this project, email SPServices@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Mar 29, 2010 at 4:17 PM

Can you post the code that *doesn't* work?  I'll see if I can reproduce the issue in my environment.

M.

Mar 29, 2010 at 4:20 PM

Certainly, here you go.

<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="https://eedshare.ontario.int.ec.gc.ca/sites/Dev/jQueryLibrary/jquery.SPServices-0.5.3.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $().SPServices.SPDisplayRelatedInfo({
     columnName: "Region",
     relatedList: "Region",
     relatedListColumn: "Region",
     relatedColumns: ["Test"],
     displayFormat: "table",
     debug: true   });
    $().SPServices.SPLookupAddNew({ 
      lookupColumn: "Region",
      promptText: "Add New {0}",
      completefunc: null,
      debug: true
    });
    $().SPServices.SPArrangeChoices({
     columnName: "Choices",
     perRow: 4
    });
   $().SPServices.SPDisplayRelatedInfo({
     columnName: "District",
     relatedList: "Regional District",
     relatedListColumn: "Title",
     relatedColumns: ["Region"],
     displayFormat: "table",
     debug: true   });
 });
</script>

Carl

Mar 29, 2010 at 7:55 PM

Oh boy. Just got everything all set up to start adding this to me pertinent fields and realize one of the major sites I'm planning on putting these scripts is a Wiki site, and the create new page is a layout form on the server. Excellent!!

Another idea for you Marc. It would be dynamite to have a script to just be able to set a URL link such as a Help page somewhere,

 

Carl

Coordinator
Mar 29, 2010 at 9:03 PM

I just tried using SPDisplayRelatedInfo and SPLookupAddNew on my Region column, in either order, and it worked fine.  Wondering if it was something else on your end.

Tell me more about the Help page idea.

M.

Coordinator
Mar 29, 2010 at 10:27 PM

p.s. I saw your post over on Waldek's site. You can use these function in a layout page, though you'll need to have the permissions to add them.

M.

Mar 29, 2010 at 11:05 PM

Hello Marc, Oh man why wouldn't be something else eh?? Well if it works for you it must be something on my end. The debug just keeps returning that error so I don't know maybe it doesn't like the names of the fields I'm using.

I didn't think you could use this on the layout page!! I was all ready to setup all my fields then remembered the list I was using on my production server was a wiki librsry which uses the layout form. I felt like had just got in the face with a pipe after having gone through all that with you then finding out it may have all been moot. BUT, if you say it works fine on layout forms then I'll have to check into it further and won't bother with the other. Thanks, that makes me feel a little better.

Now, as for the Help link, I'm a big proponent of these little tweaks that make life on a site a lot more intuitive. That's why I've been so determined to make your SPServices functions work. The link I speak of would be just a simple hyperlink one could add under any specific field and be configured to point to wherever the developer chooses with options to open either in the same window, in a new tab, in a new window, or a new window as a popup/modal window (which would be more used for instrctions). It could be used as a "Help" link for example, pointing to a URL and opening a separate window (if desired, that would be an option) providing information or instructions on the correct format or method of entering information on that particular field. That'd be pretty useful and intuitive don't you think?

This would be a real nice way for the user to be coddled/babied the way they should be, as is the case your Add New Item function and it would make the webmaster/developer look like a genius. What do you think?

Carl

Mar 30, 2010 at 6:20 PM
Thinking...The layouts page /_layouts/CreateWebPage.aspx is used by other lists isn't it? Do you it'd be more prudent to import a copy of that layouts page and it's master page into the list folder and deal with the customizations there like a regular list?
Carl


From: sympmarc [mailto:notifications@codeplex.com]
Sent: March 29, 2010 5:27 PM
To: Williams,Carl [Ontario]
Subject: Re: $().SPServices.SPLookupAddNew [SPServices:207320]

From: sympmarc

p.s. I saw your post over on Waldek's site. You can use these function in a layout page, though you'll need to have the permissions to add them.

M.

Coordinator
Mar 30, 2010 at 7:28 PM

Carl:

Any pages in _layouts are even more difficult to customize., and I wouldn't recommend it.

When you said layout page, I made the incorrect assumption that you meant a page layout, which would live in _catalogs/masterpages.  Can you explain a bit more aboiut what you are actually trying to do?

M.

Mar 30, 2010 at 7:39 PM
Certainly.

For starters I want to incorporate a few of your functions into various fields in, among other things, a wiki list. As you know, creating a new record for a wiki list, calls the /_layouts/CreateWebPage.aspx form. I think that means other wiki lists would use that particular form as well so you don't want to edit that, just copy and customize.
That's why I was mentioning it'd be better to import a copy of that and it's master page into the wiki list and point to the CreateWebPageCustom.aspx for new records. Editing forms are in the list already so that's not an issue in terms of creating a custom form for that.
Does any of that make sense?
Carl


From: sympmarc [mailto:notifications@codeplex.com]
Sent: March 30, 2010 2:29 PM
To: Williams,Carl [Ontario]
Subject: Re: $().SPServices.SPLookupAddNew [SPServices:207320]

From: sympmarc

Carl:

Any pages in _layouts are even more difficult to customize., and I wouldn't recommend it.

When you said layout page, I made the incorrect assumption that you meant a page layout, which would live in _catalogs/masterpages. Can you explain a bit more aboiut what you are actually trying to do?

M.

Mar 30, 2010 at 8:35 PM

Hmmmm.....

http://blogs.msdn.com/pavankumar/archive/2009/02/25/custom-wiki-site-definition-with-custom-document-template-for-creating-wiki-pages.aspx

I don't think I'm going to bother going to this extent just to modify a few fields in a wiki list. Why does it always hacve to be so convoluted?????????

Carl

Mar 30, 2010 at 8:41 PM

Further to my Help link suggestion. I would also use it to link to a "create new record" form for requesting certain item sbe added to a lookup list you do'nt want people changing willy-nillly. Most of mine are read-only so that'd be a great help.

CW

Coordinator
Mar 30, 2010 at 8:59 PM

So it sounds like you want to add some new columns to the Wiki Pages Document Library and apply some rules and connections between them using the functions in SPServices.  As I said before, customizing the _layout pages is a bigger deal that customizing list forms.

I haven't customized a Wiki before (it's just never come up), but it looks like you can change the default NewItem form on the Wiki Pages list just like other Document Library. By default, it's blank. I can't seem to get the setting to accept anything different, but that doesn't mean it isn't possible.

On the help thing, you do know that whatever is stored in the column's Description is shown on the form below the field?  That's where you generally add instructions on how to fill out the field.

M.

Mar 30, 2010 at 9:05 PM
Yes exactly, I won't bother with the wiki right now, it's not a hill to die on. For the help link, I hear you, but you'd have to add an ugly hyperlink instread of the nice <a href="........,</a> method, or at least Ive never been able to short of editing the form directly then ghosting/modifying the page. THen any new fields you apply to the list/ct won't show up. Unless it's Tuesday with a full moon.
 
CW
Mar 31, 2010 at 4:09 PM
Edited Mar 31, 2010 at 10:04 PM

Morning Marc,

 

I had another idea for you. I'm about to implement the unique name function and was thinking, that it'd good to popup a box to show the user if there were existing "variations" of the name being created, such as:

new name = Blog

existing variations = blog, a blog, my blog, your blog, to blog or not to blog

etc.

Carl

Coordinator
Apr 1, 2010 at 3:34 AM

Interesting thought.  I'm going to copy this to the Issue Tracker for possible inclusion down the road.

M.

Coordinator
Apr 1, 2010 at 3:34 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.