Thursday, February 5, 2009

The Java script code for searching people in MOSS 2007.

The following script will be useful in finding people in a MOSS 2007 site.

<script language="javascript">
function to handle enter on keyboard
function txtWildPeopleFinder_KeyDown(e)
{
if (e.keyCode == 13 || e.keyCode==10)
{
e.returnValue=false;
DoWildPeopleSearch();
return false;
}
else
return true;
}
escape apostrophes in search strings
function escapestr(str)
{
return str.replace("'","%22");
}

search function
function DoWildPeopleSearch()
{
var firstname = escapestr(document.all["firstname"].value);
var lastname = escapestr(document.all["lastname"].value);
var department = escapestr(document.all["department"].value);
var url;
var kString = "";

if(firstname.length > 0)
{
kString = "FirstName%3A" + firstname + "%20";
}
if(lastname.length > 0)
{
kString = kString + "LastName%3A" + lastname + "%20";
}
if(department.length > 0)
{
kString = kString + "Department%3A%22" + department + "%22";
}

url = "peopleresults.aspx?k=" + kString;
window.location=url;
return;
}
</script>

The following code gives the GUI code.

<table cellpadding="3" cellspacing="0" border="0" width="100%" ID="Table3">
<tr>
<td width="80" nowrap>
First Name:
</td>
<td width="100%">
<input size="20" maxlength="100" id="firstname" name="firstname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td width="80" nowrap>
Last Name:
</td>
<td>
<input size="20" maxlength="100" id="lastname" name="lastname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td width="80" nowrap>
Department:
</td>
<td>
<select id="department" name="department">
<option value="" selected></option>
<option value="Finance">Finance</option>
<option value="Human Resources">Human Resources</option>
<option value="Production">Production</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" onclick="DoWildPeopleSearch()" value="Search">
</td>
</tr>
</table>

No comments:

Post a Comment