Using Web Services in Sharepoint.
Please go through the below steps >>>
Required files
- SPAPI_Core.js
- SPAPI_Lists.js
Procedure:
- You can download these files from Internet (You can download from the link)
- First create one List sharepoint site with the name ‘Employee’ and fields should be ‘Title‘ & ‘Department’. Deprtment field should be LookUp field. Take data from another list with the department names.
- Upload above mentioned two files into ‘Shared document library‘
- Open that site in SharePoint designer
- Create a ‘InsertItem.aspx‘ in ‘Shared documents’ library.
- Write below code in the page.
<asp:Content id=”Content1″ runat=”Server” contentplaceholderid=”PlaceHolderMain”>
<script language=”javascript” type=”text/javascript” src=”http://192.168.1.137:5555/Shared%20Documents/SPAPI_Core.js“></script>
<script language=”javascript” type=”text/javascript” src=”http://192.168.1.137:5555/Shared%20Documents/SPAPI_Lists.js“></script>
<script language=”javascript” type=”text/javascript” src=”http://192.168.1.137:5555/Shared%20Documents/InsertItem.js“></script><table style=”font-family:Calibri;width:25%”>
<tr>
<td>
Title:
</td>
<td> <input type=”text” id=”txtTitle”></td>
</tr>
<tr><td>Department:</td>
<td><select id=”txtDepartment”>
<option value=”0″>Dept</option>
<option value=”1″>Dept1</option>
<option value=”2″>Dept2</option>
<option value=”3″>Dept3</option>
</select></td>
</tr><tr><td></td><td><button type=”submit” onclick=”AddEmployee();”>Insert</button></td></tr>
</table>
</asp:Content><asp:Content id=”Content2″ runat=”Server” contentplaceholderid=”PlaceHolderPageTitle”>
Insert Form
</asp:Content>
- After above created page, please create a JavaScript file ‘InsertCode.js‘ file with the below code.
var strUrl=”http://win2003:5555/“;
var splists = new SPAPI_Lists(strUrl);
var spuser = new SPAPI_UserGroup(strUrl);function AddEmployee()
{
if(document.getElementById(“txtTitle”).value==”"||document.getElementById(“txtDepartment”).value==”")
{
if(document.getElementById(“txtTitle”).value==”")
{
alert(‘Employee name Required..’);
}
if(document.getElementById(“txtDepartment”).value==”")
{
alert(‘Department name Required..’);
}
}
else
{
InsertItem();
}
}function InsertItem()
{
var lists=new SPAPI_Lists(strUrl);
var empName=document.getElementById(“txtTitle”).value;
var department=document.getElementById(“txtDepartment”).value;
alert(“Employee Name:”+empName);
var batch=”<Batch PreCalc=’TRUE’ OnError=’Continue’><Method ID=’1′ Cmd=’New’><Field Name=’Title’>”+document.getElementById(“txtTitle”).value+”</Field><Field Name=’Department’ Type=’LookUp’ LookUpID=’True’>”+document.getElementById(‘txtDepartment’).value+”</Field></Method></Batch>”;
var res = lists.updateListItems(“Employee”,batch);
if(res.status==200)
{
alert(‘Record Saved Successfully’);
}
else
{
alert(res.responseText);
}
}
- The above file will help to insert the item using the SPAPI files which are recommended to download from internet.
- Now open the ‘InsertTem.aspx‘ page and test the functionality.