Get list Item Using ECMA Script
var context;
var collListItem;
var itemColl;
var controlPrefix = "";
var context1;
var collListItem1;
var itemColl11;
var controlPrefix = "";
var uservalue = "";
$(document).ready(function () {
//debugger;
//ExecuteOrDelayUntilScriptLoaded(getUserData, "sp.js");
// getEmplist();
});
function getUserEmpBasicData(user,listname) {
debugger;
//listname = "EmpBasicInfo";
uservalue = user;
context = new SP.ClientContext.get_current();
list = context.get_web().get_lists().getByTitle(listname);
if (listname == "TempEmpBasicInfo") {
controlPrefix = "Old";
}
else {
controlPrefix = "New";
}
var query1 = new SP.CamlQuery();
var stryquery = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + user + "</Value></Eq></Where></Query></View>";
query1.set_viewXml(stryquery);
itemColl = list.getItems(query1);
context.load(itemColl);
context.executeQueryAsync(BasicretrieveListItemsSuccess, retrieveListItemsFail);
}
function BasicretrieveListItemsSuccess() {
debugger;
if (itemColl.get_count() > 0) {
var listItemEnumerator = itemColl.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var Title = oListItem.get_item('Title');
var EmpID = oListItem.get_item('EmpID');
var date = oListItem.get_item('DOB').getDate();
var day = oListItem.get_item('DOB').getMonth();
var Year = oListItem.get_item('DOB').getYear();
var DOB = day + '/' + date + '/' + Year;
var empFirstName = oListItem.get_item('First_x0020_Name');
var empLastName = oListItem.get_item('Last_x0020_Name');
var Designation = oListItem.get_item('Designation').get_lookupValue();
var empGender = oListItem.get_item('Gender').get_lookupValue();
var empEmailId = oListItem.get_item('VertexEmailID').get_lookupValue();
var empDepartment = oListItem.get_item('Department').get_lookupValue();
var empProfileTag = oListItem.get_item('ProfileTag');
var profile = "";
for (var i = 0; i < empProfileTag.length; i++) {
var lookupObject = empProfileTag[i];
profile += lookupObject.get_lookupValue() + ",";
}
profile = profile.substr(0, profile.length - 1) + '';
var empResidencePhoneNumber = oListItem.get_item('ResidencePhoneNumber');
var empPhone = oListItem.get_item('MobileNumber');
var empExtensionNumber = oListItem.get_item('ExtensionNumber');
var ICQNumber = oListItem.get_item('ICQNumber');
Title = Title == null ? "" : Title;
EmpID = EmpID == null ? "" : EmpID;
empFirstName = empFirstName == null ? "" : empFirstName;
empLastName = empLastName == null ? "" : empLastName;
empPhone = empPhone == null ? "" : empPhone;
ICQNumber = ICQNumber == null ? "" : ICQNumber;
empEmailId = empEmailId == null ? "" : empEmailId;
empExtensionNumber = empExtensionNumber == null ? "" : empExtensionNumber;
empGender = empGender == null ? "" : empGender;
empDepartment = empDepartment == null ? "" : empDepartment;
profile = profile == null ? "" : profile;
empResidencePhoneNumber = empResidencePhoneNumber == null ? "" : empResidencePhoneNumber;
Designation = Designation == null ? "" : Designation;
$("[id$=_lbl" + controlPrefix + "FirstName]").text(empFirstName);
$("[id$=_lbl" + controlPrefix + "LastName]").text(empLastName);
$("[id$=_lbl" + controlPrefix + "Department]").text(empDepartment);
$("[id$=_lbl" + controlPrefix + "Designation]").text(Designation);
$("[id$=_lbl" + controlPrefix + "DOB]").text(DOB);
$("[id$=_lbl" + controlPrefix + "ExtensionNumber]").text(empExtensionNumber);
$("[id$=_lbl" + controlPrefix + "ICQNumber]").text(ICQNumber);
$("[id$=_lbl" + controlPrefix + "MobileNumber]").text(empPhone);
$("[id$=_lbl" + controlPrefix + "ProfileTag]").text(profile);
$("[id$=_lbl" + controlPrefix + "ResidencePhoneNumber]").text(empResidencePhoneNumber);
}
if (controlPrefix == "Old") {
getUserEmpBasicData(uservalue, "EmpBasicInfo");
}
}
else {
$("[id$=_lblNewFirstName]").text("No Item Available");
controlPrefix = "New";
$("[id$=_lbl" + controlPrefix + "LastName]").text("");
$("[id$=_lbl" + controlPrefix + "Department]").text("");
$("[id$=_lbl" + controlPrefix + "Designation]").text("");
$("[id$=_lbl" + controlPrefix + "DOB]").text("");
$("[id$=_lbl" + controlPrefix + "ExtensionNumber]").text("");
$("[id$=_lbl" + controlPrefix + "ICQNumber]").text("");
$("[id$=_lbl" + controlPrefix + "MobileNumber]").text("");
$("[id$=_lbl" + controlPrefix + "ProfileTag]").text("");
$("[id$=_lbl" + controlPrefix + "ResidencePhoneNumber]").text("");
}
$("#PopupGVEmpBasicInfo").dialog({
title: "Employee Basic Information Changed Details",
resizable: false,
height: 350,
width: 550,
modal: true,
buttons: {
Close: function () {
$(this).dialog("close");
}
}
});
}
// This function is executed if the above call fails
function retrieveListItemsFail(sender, args) {
alert('Failed to get list items. Error:' + args.get_message());
}
var collListItem;
var itemColl;
var controlPrefix = "";
var context1;
var collListItem1;
var itemColl11;
var controlPrefix = "";
var uservalue = "";
$(document).ready(function () {
//debugger;
//ExecuteOrDelayUntilScriptLoaded(getUserData, "sp.js");
// getEmplist();
});
function getUserEmpBasicData(user,listname) {
debugger;
//listname = "EmpBasicInfo";
uservalue = user;
context = new SP.ClientContext.get_current();
list = context.get_web().get_lists().getByTitle(listname);
if (listname == "TempEmpBasicInfo") {
controlPrefix = "Old";
}
else {
controlPrefix = "New";
}
var query1 = new SP.CamlQuery();
var stryquery = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + user + "</Value></Eq></Where></Query></View>";
query1.set_viewXml(stryquery);
itemColl = list.getItems(query1);
context.load(itemColl);
context.executeQueryAsync(BasicretrieveListItemsSuccess, retrieveListItemsFail);
}
function BasicretrieveListItemsSuccess() {
debugger;
if (itemColl.get_count() > 0) {
var listItemEnumerator = itemColl.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var Title = oListItem.get_item('Title');
var EmpID = oListItem.get_item('EmpID');
var date = oListItem.get_item('DOB').getDate();
var day = oListItem.get_item('DOB').getMonth();
var Year = oListItem.get_item('DOB').getYear();
var DOB = day + '/' + date + '/' + Year;
var empFirstName = oListItem.get_item('First_x0020_Name');
var empLastName = oListItem.get_item('Last_x0020_Name');
var Designation = oListItem.get_item('Designation').get_lookupValue();
var empGender = oListItem.get_item('Gender').get_lookupValue();
var empEmailId = oListItem.get_item('VertexEmailID').get_lookupValue();
var empDepartment = oListItem.get_item('Department').get_lookupValue();
var empProfileTag = oListItem.get_item('ProfileTag');
var profile = "";
for (var i = 0; i < empProfileTag.length; i++) {
var lookupObject = empProfileTag[i];
profile += lookupObject.get_lookupValue() + ",";
}
profile = profile.substr(0, profile.length - 1) + '';
var empResidencePhoneNumber = oListItem.get_item('ResidencePhoneNumber');
var empPhone = oListItem.get_item('MobileNumber');
var empExtensionNumber = oListItem.get_item('ExtensionNumber');
var ICQNumber = oListItem.get_item('ICQNumber');
Title = Title == null ? "" : Title;
EmpID = EmpID == null ? "" : EmpID;
empFirstName = empFirstName == null ? "" : empFirstName;
empLastName = empLastName == null ? "" : empLastName;
empPhone = empPhone == null ? "" : empPhone;
ICQNumber = ICQNumber == null ? "" : ICQNumber;
empEmailId = empEmailId == null ? "" : empEmailId;
empExtensionNumber = empExtensionNumber == null ? "" : empExtensionNumber;
empGender = empGender == null ? "" : empGender;
empDepartment = empDepartment == null ? "" : empDepartment;
profile = profile == null ? "" : profile;
empResidencePhoneNumber = empResidencePhoneNumber == null ? "" : empResidencePhoneNumber;
Designation = Designation == null ? "" : Designation;
$("[id$=_lbl" + controlPrefix + "FirstName]").text(empFirstName);
$("[id$=_lbl" + controlPrefix + "LastName]").text(empLastName);
$("[id$=_lbl" + controlPrefix + "Department]").text(empDepartment);
$("[id$=_lbl" + controlPrefix + "Designation]").text(Designation);
$("[id$=_lbl" + controlPrefix + "DOB]").text(DOB);
$("[id$=_lbl" + controlPrefix + "ExtensionNumber]").text(empExtensionNumber);
$("[id$=_lbl" + controlPrefix + "ICQNumber]").text(ICQNumber);
$("[id$=_lbl" + controlPrefix + "MobileNumber]").text(empPhone);
$("[id$=_lbl" + controlPrefix + "ProfileTag]").text(profile);
$("[id$=_lbl" + controlPrefix + "ResidencePhoneNumber]").text(empResidencePhoneNumber);
}
if (controlPrefix == "Old") {
getUserEmpBasicData(uservalue, "EmpBasicInfo");
}
}
else {
$("[id$=_lblNewFirstName]").text("No Item Available");
controlPrefix = "New";
$("[id$=_lbl" + controlPrefix + "LastName]").text("");
$("[id$=_lbl" + controlPrefix + "Department]").text("");
$("[id$=_lbl" + controlPrefix + "Designation]").text("");
$("[id$=_lbl" + controlPrefix + "DOB]").text("");
$("[id$=_lbl" + controlPrefix + "ExtensionNumber]").text("");
$("[id$=_lbl" + controlPrefix + "ICQNumber]").text("");
$("[id$=_lbl" + controlPrefix + "MobileNumber]").text("");
$("[id$=_lbl" + controlPrefix + "ProfileTag]").text("");
$("[id$=_lbl" + controlPrefix + "ResidencePhoneNumber]").text("");
}
$("#PopupGVEmpBasicInfo").dialog({
title: "Employee Basic Information Changed Details",
resizable: false,
height: 350,
width: 550,
modal: true,
buttons: {
Close: function () {
$(this).dialog("close");
}
}
});
}
// This function is executed if the above call fails
function retrieveListItemsFail(sender, args) {
alert('Failed to get list items. Error:' + args.get_message());
}
Comments