Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1217
  • Last Modified:

How can I pull the ID from a Lookup field in WSS 3.0

Hi experts:
Given two lists: lstStudents and lstReview where lstReview contains a lookup field to the 'Student Name' in lstStudents, how can I get the ID of the referenced student?

From my initial searching it seems there used to be a fairly easy way to accomplish this in WSS 2.0 and FrontPage, where you would just serparate the returned value on the '#' and the first part of the field would ID. It doesn't seem like this method works using WSS 3.0 with SDP 2007.

I also came across a reference to using the ddwrt:Urllookup function to accomplish this but when I tried <xsl:value-of select="ddwrt:UrlLookup('{GUID-of-List}','Student',string(@ID))"/> it doesn't return anything.

This seems like it should be simple, and I just know I'm going to facepalm when I get the answer!
0
steam23
Asked:
steam23
1 Solution
 
zephyr_hex (Megan)DeveloperCommented:
i can provide a little information about the structure behind lookups, although this doesn't answer your question directly.

see here:
http://she-nerdles.blogspot.com/2009/12/finding-elusive-lookup-field-with-sql.html
0
 
raybiesCommented:
All you need to do is split the string by ;#

So it will look like this:

<id>;#<title>
4;#steam23


U can use javascript, C#... it's just a split.

var myLU = "4;#steam23";
var myID = myLU.split(";#")[0];
0
 
steam23Author Commented:
Zaphyr Hex: That's an interesting articel. I'm going to play around with that if only to see a bit more of what's going on under the hood.
Raybies: Are you sure that is the case for WSS 3.0? Like I said I remember doing that kind of transformation with Wss 2.0 (with xsl) but I think they changed the way it works in 3.0.
 Here's the script I just tried:
       <script type="text/javascript">
       var luStudent = <xsl:value-of select="@Student"/>;
       var idStudent = luStudent.split(";#")[0];
       Document.write idStudent
       </script>
To be fair, I'm not to familiar with mixing javascript an xslt in this fashion so I may be doing it wrong. However, the script as above didn't get any result.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
raybiesCommented:
steam23: I'm sure WSS3 stores lookups as <id>;#<title>

But your js is wrong. <xsl:value-of select="@Student"/> is not a valid string for the script engine.

Try setting a hidden input field value to <xsl:value-of select="@Student"/>, then using javascript like

<script type="text/javascript">
      var luStudent = document.getElementById('myHiddenFld').value;
      var idStudent = luStudent.split(";#")[0];
      Document.write idStudent
</script>

'myHiddenFld' should be unique id on the page.
0
 
steam23Author Commented:
sorry i didn't get to this sooner, I've been busy getting stuff wrapped up for year end.. so it goes.
I tried the changes you suggested, still with no result. Here's the code I used:
      <td width="25%" class="ms-vb">
         <SharePoint:FormField runat="server" id="student" controlmode="Edit" fieldname="Student" itemid="{@ID}" __designer:bind="{ddwrt:DataBind('u','student','Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Student')}" />
      </td>
      <td width="75%" class="ms-vb">
       <script type="text/javascript">
       var luStudent = document.getElementById('student').value;
       var idStudent = luStudent.split(";#")[0];
       Document.write idStudent
       </script> </td>
 
With that code, I can see the sharepoint field no problem, but it's blank where the ID should be. For the record, I've tried formatting the Student field as a SP List Field, Text box and a label, all with the same result.
 
0
 
raybiesCommented:
OK... I think I understand the issue.... your not getting back the ID of the lookup at all.

Read this: http://social.msdn.microsoft.com/Forums/fi-FI/sharepointcustomization/thread/38745080-9f07-4121-bb61-db9fde4b8f22


It seems like the only way is to join the 2 lists together and get the ID.

http://office.microsoft.com/en-us/sharepointdesigner/HA101154041033.aspx
http://blah.winsmarts.com/2007-10-Performing_joins_between_SharePoint_lists.aspx


By the way if you did have a string with <id>;#<title> the below works 100%, just save as an html file.


<html>
<head>
</head>
<body> 
<input type="text" id="student" value="123;#Student Name">
<script type="text/javascript">
var luStudent = document.getElementById('student').value;
var arStudent = luStudent.split(";#");
alert("ID = "+ arStudent[0] +"\nName = "+ arStudent[1]);
document.write("ID = "+ arStudent[0] +"\nName = "+ arStudent[1]);
</script>
</body> 
</html>

Open in new window

0
 
adlink_laCommented:
Using SPDesigner in a clean web page (with attached master page if you want)

1)  open Data Source Library (menu bar -> Task Panes - Data Source Library)
2)  now that you have a list of list libraries in design view, right click on the student list library and click "insert data source control"
3) right click this datasource and make sure to choose ID and student name as your columns.  Make any other filter and sorting configurations at this point.
4)  then, open the toolbox and drag on drop a asp:dropdown (or datalist) control on your web page (do not drop into web part zone this will not work)
5)  right click on your dropdown control and go into the properties where you'll select the data source from step #2.
6) now create a data form web part (hope you know how to that) and drop that into a web part zone.
7)  you should still be in design view, so highlight this new DVWP using the mouse and on the SPD menu "Data View" find "Data View Parameters".
8)  Create a new parameter, call it "prmID"  and set the parameter source = Form and set the Form Field to the name of that drop down control from step 4.  Remember, this is an asp control so the name of this control would be something like "ctl00$PlaceHolderMain$DropDownList1".
9) Now, after you've completed these steps you can access the ID inside your DVWP using XSLT.  Here is the code for that:
<xsl:value-of select="$prmID"/>

A few steps but it works for me and it is very flexible solution.  

Good luck.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now