Use $().SPServices.SPDisplayRelatedInfo to write field value?

Dec 7, 2009 at 9:00 PM

Marc,

I am new"er" to JQuery so forgive my naivete. I am using the SPDisplayRelatedInfo which is working very nicely thank you. I would like to populate a column displayed on the form with the result from the RelatedInfo lookup. Is there an easy way to do this? Can I grab the value from the function and use some JS to populate my form's column value?

Coordinator
Dec 7, 2009 at 9:03 PM

There are no dumb questions -- unless you ask the same question more than 3 times. ;+)

This is an idea on my list of enhancements. Would you want to select the value for the column driving the SPDisplayRelatedInfo function or a different column?

M.

Dec 7, 2009 at 9:14 PM

In my case, I have a Vendor pull down (standard SP column Lookup) to a Vendors List. I am using the SPDisplayRelatedInfo to retrieve the Vendor ID from the same Vendors List based on the Vendor name. I have a requirement to store the Vendor ID not necessarily the name although the users need to see the Vendor Name to actually make their selection. So, in my case, I am only returning a unique value based on the Vendor name but to answer your question for a more robust, reusable solution; It would be great to be able to set a form field (column) based on any of the fields/columns you have specified as return data from the SPDisplayRelatedInfo.

e.g.

Origininal

$().SPServices.SPDisplayRelatedInfo({

      columnName: "Vendor",

      relatedList: "Vendors",

      relatedListColumn: "Title",

      relatedColumns: ["VendorID"],

      displayFormat: "list",

      headerCSSClass: "ms-hidden",

      debug: false

});

New

$().SPServices.SPDisplayRelatedInfo({

      columnName: "Vendor",

      relatedList: "Vendors",

      relatedListColumn: "Title",

      relatedColumns: ["VendorID","VendorName"],

      displayFormat: "list",

      headerCSSClass: "ms-hidden",

      columnAssignment: ["MyVendorID:VendorID"]

      debug: false

});

In my example, the “VendorID” in the relatedColumns is getting assigned to the “MyVendorID” column in my current form where the value will get populated. This is not to say that the current functionality would be removed. I can use the ms-hidden to hide what I need to.

Also, if I have overlooked an easier way to accomplish what I have described, please let me know. To my knowledge there is no easy way to display a pull down with one value and store/save a different value like in a normal HTML Select input.

Thank you so much in advance for your contributions and your assistance.

From: sympmarc [mailto:notifications@codeplex.com]
Sent: Monday, December 07, 2009 4:03 PM
To: Walker, Allan
Subject: Re: Use $().SPServices.SPDisplayRelatedInfo to write field value? [SPServices:77400]

From: sympmarc

There are no dumb questions -- unless you ask the same question more than 3 times. ;+)

This is an idea on my list of enhancements. Would you want to select the value for the column driving the SPDisplayRelatedInfo function or a different column?

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
Dec 8, 2009 at 3:53 AM

Interesting approach.  So, in fact, you don't really want to store the VendorName in the list, but just the VendorID.  When you have a Lookup column, the ID of the Lookup value is actually stored in the list as well, in a format like this: ID;#value so e.g., 123;#Lester's Appliance Repair.

So I'm wondering if you actually want to do what you are proposing.  There's really no harm in storing the name rather than the ID, but I guess it all depends on what you are going to need to do with it later.

Another approach on this would be to put some script into the PreSaveAction function to grab the index value of VendorName and store it in VendorID. But you'll still be storing VendorName, which is redundant.

I'll think some more about this...

M.

Dec 8, 2009 at 4:35 AM
To be clear, I ultimately would like to mimic the native HTLM Select where I have a value that is displayed to a user but a different value is stored.

<select>
<option value="000012345">IBM Global Corp.</option>
<option value="000987654">Catapult</option>
<option value="000102938">Xcelligent</option>
<option value="000005678">Microsoft</option>
</select>

This would translate to a Lookup column that would display a Vendor Name but store the Vendor ID.
(ID;#value so e.g., 25;#000012345 where the "25" is the normal List ID not the Vendor ID)

I am using a workflow to retrieve the VendorID from my Vendors List and store it in my Invoice record based on the Vendor Name that the user selected which works of course. I guess I am a little old fashioned and feel the need to have the information I want on the screen and ready to store when the user submits the form.

The issue is that the Vendor Name can be changed so IBM Global Corp. may be modified to IBM Global. If that happens, I would anticipate problems. It would be better to store the Vendor's ID which will never change no matter their name. It is just more difficult for a user to know which Vendor they are selecting when all they have is the number only.

I hope this makes it a little more clear. My original thought was to use your function to get the related VendorID based on the Vendor Name and essentially populate the value for the user into a text field (column) on my form.


Again, thank you for your assistance. I would love to know how you are able to contribute so much of your time, I would love to do the same for the community.

Regards,
Allan Walker
Lead Business Analyst - SharePoint
Kforce Professional Staffing
813-552-2096 [office]
813-841-1645 [cell]
www.kforce.com

Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.



-----Original Message-----
From: sympmarc [mailto:[email removed]
Sent: Mon 12/7/2009 10:53 PM
To: Walker, Allan
Subject: Re: Use $().SPServices.SPDisplayRelatedInfo to write field value? [SPServices:77400]

From: sympmarc

Interesting approach. So, in fact, you don't really want to store the VendorName in the list, but just the VendorID. When you have a Lookup column, the ID of the Lookup value is actually stored in the list as well, in a format like this: ID;#value so e.g., 123;#Lester's Appliance Repair.

So I'm wondering if you actually want to do what you are proposing. There's really no harm in storing the name rather than the ID, but I guess it all depends on what you are going to need to do with it later.

Another approach on this would be to put some script into the PreSaveAction function to grab the index value of VendorName and store it in VendorID. But you'll still be storing VendorName, which is redundant.

I'll think some more about this...

M.

Read the full discussion online <http://spservices.codeplex.com/Thread/View.aspx?ThreadId=77400&ANCHOR#Post264729> .

To add a post to this discussion, reply to this email ([email removed] <mailto:[email removed]?subject=[SPServices:77400]> )

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe <http://www.codeplex.com/site/discussions/thread/unsubscribe/77400> 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
Dec 8, 2009 at 4:56 AM

Ok, I see where you are going with this.  I was thinking the item's ID, not a real VendorID; sorry.

So if you keep the form as the out of the box LFWP, then you'll need to have a VendorName and a VendorID column on the list. Both will be stored in the list items.

If we run through the use case:

  • The user selects a value for VendorName from the dropdown (select)
  • SPDisplayRelatedInfo shows the VendorID and VendorName (based on your example code above). There wil only be one mathing vendor, since the dropdown has unique values, correct?
  • Then what? Do we just capture the corresponding VendorID and populate the VendorID column? Do you want the VendorID column visible on the form?

I'm thinking in the short term that you could just use the completefunc I've just added to SPDisplayRelatedInfo in v0.4.7.  It's still an alpha, but I think it's in decent shape: http://spservices.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36650

With SPDisplayRelatedInfo, the output for each column is wrapped in a div: 

var divId = "showRelated_" + encodeColumn(opt.columnName);

So, in this case the div's id would be showRelated_Vendor.  You can add a little jQuery to the completefunc to grab the value of VendorID inside the div and set the VendorID column on the form.  Make sense?

As for my time, well, I'm a masochist.  Just kidding.  Seriously, I do it because I enjoy it.  I have my own consulting company, so I get to decide what I work on around my client work, and this library is one of the big things I've decided to do.

M.

Dec 8, 2009 at 5:19 AM
I think your completefunc will do the trick according to your example. Ironic when I was typing my last response to you I was thinking that if you were wrapping the values in div's with classes or id's I could grab the values. I will d/l it in the a.m. while in my 8 hour requirements meeting and give it a go.

To further answer some of your questions and help elaborate more:

* User selects a Vendor Name from a pulldown (select/Lookup) column on the form (LFWP)
* SPDisplayRelatedInfo retrieves and displays the Vendor ID. (The Vendor Name is not necessary to retrieve as the user just selected it.)
* Capture the corresponding VendorID and populate a VendorID column on the LFWP. It would be preferred to have the VendorID column hidden but that is again another feature that is not available OOB. (So many simple things overlooked or left out in 2007, can't wait until 2010.)

I respect and admire your devotion. I will admit that I left programming a few years ago as a Java programmer to "take a break" as the hours were starting to impact my family. While I do not regret my decision based on the circumstances, I regret that I have not been able to get back over to our development team due to lack of availability. I have a strong passion for programming and SharePoint. I try to keep up my skills a bit by doing some development on my own. I have realized when programming is not your full time job it is difficult to keep up with the ever changing technology. Our company has yet to also embrace SharePoint as an application platform so recently I accepted a position as a SharePoint Business Analyst for some of our LOB's. I have hopes that I can help them understand the potential and kick start the need to grow our development team a little. Enough of the filler conversation. I'll allow you your sleep. Thank you again for your assistance.

Regards,
Allan Walker
Lead Business Analyst - SharePoint
Kforce Professional Staffing
813-552-2096 [office]
813-841-1645 [cell]
www.kforce.com

Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.



-----Original Message-----
From: sympmarc [mailto:[email removed]
Sent: Mon 12/7/2009 11:56 PM
To: Walker, Allan
Subject: Re: Use $().SPServices.SPDisplayRelatedInfo to write field value? [SPServices:77400]

From: sympmarc

Ok, I see where you are going with this. I was thinking the item's ID, not a real VendorID; sorry.

So if you keep the form as the out of the box LFWP, then you'll need to have a VendorName and a VendorID column on the list. Both will be stored in the list items.

If we run through the use case:

* The user selects a value for VendorName from the dropdown (select)
* SPDisplayRelatedInfo shows the VendorID and VendorName (based on your example code above). There wil only be one mathing vendor, since the dropdown has unique values, correct?
* Then what? Do we just capture the corresponding VendorID and populate the VendorID column? Do you want the VendorID column visible on the form?

I'm thinking in the short term that you could just use the completefunc I've just added to SPDisplayRelatedInfo in v0.4.7. It's still an alpha, but I think it's in decent shape: http://spservices.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36650

With SPDisplayRelatedInfo, the output for each column is wrapped in a div:

var divId = "showRelated_" + encodeColumn(opt.columnName);


So, in this case the div's id would be showRelated_Vendor. You can add a little jQuery to the completefunc to grab the value of VendorID inside the div and set the VendorID column on the form. Make sense?

As for my time, well, I'm a masochist. Just kidding. Seriously, I do it because I enjoy it. I have my own consulting company, so I get to decide what I work on around my client work, and this library is one of the big things I've decided to do.

M.

Read the full discussion online <http://spservices.codeplex.com/Thread/View.aspx?ThreadId=77400&ANCHOR#Post264747> .

To add a post to this discussion, reply to this email ([email removed] <mailto:[email removed]?subject=[SPServices:77400]> )

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe <http://www.codeplex.com/site/discussions/thread/unsubscribe/77400> 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
Dec 8, 2009 at 2:19 PM

Allan:

I'm not sure that SharePoint 2010 is going to be the panacea you're looking for: the devil is in the details.  Since you're already going to use jQuery on the form, just use it to hide the VendorID column as well.  You may also be able to get away with using ms-hidden for the table in SPDisplayRelatedInfo, but I haven't tested this.  While you're using SPDisplayRelatedInfo, you're not really interested in having it show you anything, though it might be useful for the user to see a few more columns about the vendor so that they are sure they have chosen the right one, like maybe address or something; whatever you've stored in your vendor list that might be helpful.

M.

Jan 7, 2010 at 5:11 PM

Ok, I'm finally back from vacations etc and can get back into this. I know this has to be obvious (not to me currently) but I am simply trying to get an alert popup and can't seem to get it. The functionality of displaying the related columns info is working fine, it just doesn't seem that the completefunc is working. I am using SPServices 0.4.7 which I have confirmed has the code for the completefunc but digress as to what is causing this simple alert to not pop.

$().SPServices.SPDisplayRelatedInfo({
	columnName: "Vendor",
	relatedList: "Vendors",
	relatedListColumn: "Title",
	relatedColumns: ["VendorID"],
	displayFormat: "list",
	debug: true,
    completefunc: function(xData, Status) { 
		alert("hello");
    }
});

Anything glaringly obvious?

Coordinator
Jan 7, 2010 at 7:32 PM

The issue is that you've got xData and Status in your completefunc.  They don't have any meaning here and are undoubtedly the issue. Try this:

$().SPServices.SPDisplayRelatedInfo({
	columnName: "Vendor",
	relatedList: "Vendors",
	relatedListColumn: "Title",
	relatedColumns: ["VendorID"],
	displayFormat: "list",
	debug: true,
         completefunc: function() { 
		alert("hello");
         }
});

M.

Jan 7, 2010 at 7:50 PM
Edited Jan 7, 2010 at 8:00 PM

I gave it a try and still no alert box. I unfortunately cannot debug it via Internet Explorer Dev Tools (IE8). I have not had any issues in the last few weeks getting alerts. I used them pretty extensively when testing the workflow stuff I was working on. Any suggestions on debug methods?

Coordinator
Jan 7, 2010 at 7:56 PM

Can you use Firebug?  Also try separating the alert out into another function like I show in the docs.

M.

Jan 7, 2010 at 9:10 PM

Ok, I got Firebug up and running and did some stepping. I don't really believe what I found though. I was able to get into your SPServices library (.js) file and couldn't see the completefunc code in the SPRelatedInfo function. I scrolled to the top and it shows Version 0.4.5 not 0.4.7 which would explain a few things. I don't think it has anything to do with browser cache since this was a fersh mozilla install and this is the first site I have used with it. Somehow, it seems, SharePoint is caching the .js file and not updating it. Any suggestions barring an IISRESET?

Coordinator
Jan 7, 2010 at 9:34 PM

Silly question, but is your reference to the library right (v0.4.7 rather than v0.4.5)?  I just checked, and v0.4.7 does indeed have the right version number in it.  If you just installed Firefox, then you're right that it can't be the browser cache.

M.

Jan 7, 2010 at 9:53 PM

Whether it is best practice or not; I have renamed you library to jquery.SPServices (excluding the version number) and uploaded it to a Document Libaray on my site. All of my CEWP's reference the script by relative URL. I'll upload the file using the long name and change the reference in my scripts to see if that helps temporarily.

Coordinator
Jan 7, 2010 at 9:56 PM

Not bad practice as long as you know what you've got!  Version management can be a headache, so whatever works for you consistently is the right answer.  If you only have jquery.SPServices and you're seeing 0.4.5, though...

M.

Jan 8, 2010 at 12:23 AM

Not to stray on topic but I track the version number of your library as well as others like jquery 1.3.2 in the Document Library to help keep versioning of the library straight. I finally got the correct version (0.4.7) loading but I hesitate to tell you why it wasn't to begin with. I'll have to come up with some elaborately long and boring diatribe that is not true to give you some other day. None-the-less, As usual, your library is working very well now. On to finishing this final test to use the combination of the completefunc and some magic to write the returned value to a field using your previous example far above.

Coordinator
Jan 8, 2010 at 1:15 AM

Your secret is safe with me (and whoever else reads this thread!).

M.