SPLookupAddNew

Nov 3, 2009 at 1:57 PM


Hey there, I'm trying to get the SPLOOKUPADDNEW function to work on my create new custom list form.  That is, I've created a custom list form that adds an office with has lookup field for Region (this is pretty close to the example found on the doc page). The needed javascript is found just below the contentplaceholderid="PlaceHolderMain", and I've added a simple alert to the $(document).ready(function() to check if the funtion is loading and it seems to be.  The issue, is that I'm expecting the link to appear under the region field, but not shows up.

I've been able to get other jquery sp tools to work so I'm not sure what I'm missing.

-Ryan

Coordinator
Nov 3, 2009 at 2:27 PM

It's always possible that there's a bug!

The function takes the DisplayName of the column, though it sounds like your column is called Region, which would have the same DisplayName and StaticName.  What type of other customizations have you done on the form? 

M.

Nov 3, 2009 at 2:45 PM

Hey there, I just created a new ASPX page that is found in a document library folder (not the lists folder), attached my master page, created a custom list form based on the office list (which has a lookup on the Region list).  On this form I added that javascript (the include files for the javascript libraries are in the master page both the jQuery JavaScript Library v1.3.2 and jquery.SPServices-0.4.1).  Region is the display name and Title is the internal name (ie Region is a custom list which has one column and I renamed Title to be Region).

-Ryan

 

Coordinator
Nov 5, 2009 at 10:15 PM

Sorry, Ryan. I think I dropped the ball on this.  Did you get it to work?

M.

Coordinator
Nov 10, 2009 at 4:13 AM

Ryan:

There is a bug when there are 20+ items in the dropdown.  I have a fix for this if you need it, and the next release will contain the fix, of course.

M.

Nov 10, 2009 at 12:29 PM

Hey there, if you have the fix that would be a great help.

 

Thanks,

-Ryan

 

Nov 10, 2009 at 6:53 PM

Hey there, I was able to get the function to work using the V0.5 Alpha for the default Newform and editform forms for a list. 

BTW, Does this function support being used in a custom list form (either edit or new)?

 

-Ryan

 

Coordinator
Nov 10, 2009 at 7:02 PM

Ryan:

Glad to hear that worked for you.  Watch for a new release (v0.4.5) later today.

Yes, it will work on a custom form as long as you are using the default controls for each column.

M.

Nov 11, 2009 at 8:44 PM

Hey there, the strange thing seems to happen that on another list the link does not show up, and the debug doesn't return any errors (debug will return an error if I input junk for the lookupColumn field).  Looking at the SPLookupAddNew code it looks like the status returned from the first call to $().SPServices will return error.  Do you know of any way to try to find out what the error message might be returned from the webservice call?

 

Thanks,

-Ryan

 

Coordinator
Nov 11, 2009 at 8:55 PM

Ryan:

I think we just came up with a way to enhance the debug mode. ;+)  If you want to see what the Web Service calls return, use the SPDebugXMLHttpResult function:
http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices.SPDebugXMLHttpResult
or add an alert in the completefunc like this:

alert(xData.responseXML.xml);

M.

 

Nov 12, 2009 at 1:22 PM

Thanks once more, looks like my issue is that for the lists it fails is when the list name was changed.  For example the list URL might be Post, the title of the list was changed to Posts so the call to the getlists will fail because the listname in the xml is Post when it should be Posts.  This was most likely the issue I was having last week were I was creating the custom page from another folder to a list, so the param in the xml for listname was wrong.

-Ryan

 

Nov 12, 2009 at 1:47 PM

They there, forgot to mention I was able to add another param to the function to allow the user to add the list name and this seems to do the trick.  I can post the change here if you would like.

 

-Ryan

 

Coordinator
Nov 13, 2009 at 12:39 PM

Interesting.  As you saw, I'm grabbing the list name from the URL, which is probably a bit weak.  I'm definitely interested in what you added to get it working.

M.

Nov 13, 2009 at 12:51 PM

Hey there, I added another param, and defaulted to the url info if the param was not filled in - here is the top part of the function that was modified:

 $.fn.SPServices.SPLookupAddNew = function(options) {

  var opt = $.extend({}, {
   listName: "",
   lookupColumn: "",    // The display name of the Lookup column
   promptText: "Add new {0}",  // Text to use as prompt + column name
   debug: false     // If true, show error messages; if false, run silent
  }, options);

  // Find the lookup column's select (dropdown)
  var lookupSelect = new dropdownCtl(opt.lookupColumn);
  
  var listName = opt.listName;
  if(listName  == ""){ listName = listNameFromUrl();}
  
  if(lookupSelect.Obj.html() == null && opt.debug) { errBox("SPServices.SPLookupAddNew", "lookupColumn: " + opt.lookupColumn, "Column not found on page"); return; }

  var newUrl = "";
  var lookupListUrl = "";
  // Use GetList for the current list to determine the details for the Lookup column
  $().SPServices({
   operation: "GetList",
   async: false,
   listName: listName ,
   completefunc: function (xData, Status) {

........ Rest of function listed as is .........

 

-Ryan

 

 

 

Coordinator
Nov 13, 2009 at 2:05 PM
Edited Nov 13, 2009 at 6:35 PM
That'll certainly work, but I think I need to come up with something better than listNameFromUrl(). I have an idea for using GetListCollection. Stay tuned!

M.
Nov 13, 2009 at 6:33 PM

Hey Ryan,

You saved (a part of) my day :) I had the same problem and after copying your code, the issue with renamed lists was solved.

Thx for posting your solution!

@ Marc: should it be nice if the new added value is automatic selected into the drop down box?

Coordinator
Nov 13, 2009 at 6:37 PM

Martijn:

Glad Ryan's fix worked for you as well.  I obviously have some weak code I need to fix there.  What do you mean by "the new added value is automatic selected into the drop down box"?

M.

Coordinator
Nov 13, 2009 at 6:39 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 13, 2009 at 6:48 PM
  1. A user goes to the NewForm of a list to insert a new record
  2. The lookup column (for example the Region column of Ryan above) doesn't contain the value he/she needs.
  3. So they hit the link (created by the SPlookupAddNew function) to insert a new value into the lookup column (the list which contains the values for the drop down box)
  4. After returning to the NewForm of step 1 they need to manually select this new created lookup value.

Shouldn't it be nice if the new created value of the lookup column at step 3 is automatically selected? I think if an user adds a new value to the lookup column - using the link created with your SPLookUpAddNew function - they (always) want to use this value to create the new record?

Martijn

Coordinator
Nov 13, 2009 at 6:51 PM
Edited Nov 13, 2009 at 6:53 PM
Aha. I see what you mean. I'll take a look at it!
M.
Coordinator
Nov 13, 2009 at 6:54 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Nov 19, 2009 at 4:31 AM

Ryan and Martijn:

I've got a potential fix in place in the latest v0.4.6ALPHA: http://spservices.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=35830 If you have the time, could you test it out where you were having the problems with SPLookupAddNew?

Thanks,
M.

Dec 29, 2009 at 7:56 AM

Hey Marc,

I just tested it at a test environment and it works fine for me now, great job!

Happy hollidays,

Martijn

Coordinator
Dec 29, 2009 at 8:26 PM

Thanks, Martijn.  I still have your other idea on the issues list about setting the dropdown to the just-added value.  Stay tuned!

M.

Dec 31, 2009 at 10:13 AM

Thx Marc, I noticed it and will definitely stay tuned! J

Happy 2010!

Martijn

Met vriendelijke groet,

Martijn Molegraaf

06 24 97 17 89

m.molegraaf@ETTU.NL

Dit bericht bevat vertrouwelijke informatie die uitsluitend bestemd is voor de geadresseerde(n). Indien dit bericht niet voor u is bestemd, is openbaarmaking, vermenigvuldiging, verspreiding en/of het ondernemen van eventuele acties op basis van de inhoud van deze informatie, strikt verboden. Indien u dit bericht abusievelijk heeft ontvangen, wordt u verzocht m.molegraaf@ETTU.NL hiervan onmiddellijk per e-mail op de hoogte te brengen en het bericht vervolgens van uw systeem te verwijderen. Veilige en foutvrije verzending van e-mails kan niet worden gewaarborgd. Berichten kunnen bijvoorbeeld worden onderschept, beschadigd, vernietigd of vertraagd, verloren gaan, een deel van hun inhoud verliezen of met een virus worden geïnfecteerd. Martijn Molegraaf aanvaardt geen aansprakelijkheid voor eventuele fouten of weglatingen in dit bericht, enig deel van dit bericht, of in de bijlagen, die het gevolg zijn van de verzending. Vraag ons indien nodig om een afdruk van het oorspronkelijke bericht voor verificatie van de inhoud.


From: sympmarc [mailto:notifications@codeplex.com]
Sent: dinsdag 29 december 2009 21:27
To: Martijn Molegraaf
Subject: Re: SPLookupAddNew [SPServices:73919]

From: sympmarc

Thanks, Martijn. I still have your other idea on the issues list about setting the dropdown to the just-added value. Stay tuned!

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