var siteurl = _spPageContextInfo.webAbsoluteUrl;
var acctNo;
var acctDesc;
var acctJst;
var comment;
var currentUserName;
var currentUserEmail;
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getItem);
$(function() {
$.ajax({
url: siteurl + "/_api/web/currentuser",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
//console.log(data);
currentUserName = data.d.Title;
currentUserEmail = data.d.Email;
document.getElementById("userName").value = currentUserName;
document.getElementById("userEmail").value = currentUserEmail;
},
error: function (data) {
alert("Error: "+ data);
}
});
});
function getItemDetails(){
var itemId = getParameterByName('id');
url: siteurl + "/_api/web/lists/GetByTitle('Purchase Requisition')/items?$select=Id",
$.ajax({
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
empID = data.d.results[0].Id;
},
error: function (data) {
console.log("Error: "+ data);
}
});
}
function getItem()
{
var itemId = getParameterByName('id');
if(itemId){
var camlQuery = new SP.CamlQuery();
prList = webObj.get_lists().getByTitle('Purchase Requisition');
itemVals = prList.getItemById(itemId);
curCtx.load(itemVals);
curCtx.executeQueryAsync(Function.createDelegate(this, this.onItemLoadSuccess), Function.createDelegate(this, this.onFail));
}
}
function onItemLoadSuccess(sender, args){
var glAccount = itemVals.get_item("G_x002f_L_x0020_Account_x0020_nu");
alert(glAccount);
}
function addDetails()
{
acctNo = $('#accntNo').val();
acctDesc = $('#accntDesc').val();
acctJst = $('#accntJust').val();
comment = $('#comment').val();
if(currentUserName=="" || currentUserEmail=="" || acctNo=="")
{
alert("Please fill all the mandatory fields...");
}
else
{
var context = SP.ClientContext.get_current();
context.executeQueryAsync(function(){
var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle("Purchase Requisition");
var newEventCreateInfo = new SP.ListItemCreationInformation();
var newEvent = list.addItem(newEventCreateInfo);
newEvent.set_item("G_x002f_L_x0020_Account_x0020_nu",acctNo);
newEvent.set_item("Account_x0020_Description",acctDesc);
newEvent.set_item("Account_x0020_justification_x002",acctJst);
newEvent.set_item("Comments",comment);
newEvent.set_item("User_x0020_Name",currentUserName);
newEvent.set_item("User_x0020_Email",currentUserEmail);
newEvent.update();
context.executeQueryAsync(function(){alert("Datae has been added successfully...");},function(){alert("Something went wrong!!! Please try again...");})
},
function(sender, args){
alert(args.get_message());
});
}
}
//Get Query string parameters
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
//update Query string values
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
if (uri.indexOf('#') > -1) {
uri = uri.split('#')[0];
uri = uri.replace('#', '');
}
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}
var acctNo;
var acctDesc;
var acctJst;
var comment;
var currentUserName;
var currentUserEmail;
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getItem);
$(function() {
$.ajax({
url: siteurl + "/_api/web/currentuser",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
//console.log(data);
currentUserName = data.d.Title;
currentUserEmail = data.d.Email;
document.getElementById("userName").value = currentUserName;
document.getElementById("userEmail").value = currentUserEmail;
},
error: function (data) {
alert("Error: "+ data);
}
});
});
function getItemDetails(){
var itemId = getParameterByName('id');
url: siteurl + "/_api/web/lists/GetByTitle('Purchase Requisition')/items?$select=Id",
$.ajax({
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
empID = data.d.results[0].Id;
},
error: function (data) {
console.log("Error: "+ data);
}
});
}
function getItem()
{
var itemId = getParameterByName('id');
if(itemId){
var camlQuery = new SP.CamlQuery();
prList = webObj.get_lists().getByTitle('Purchase Requisition');
itemVals = prList.getItemById(itemId);
curCtx.load(itemVals);
curCtx.executeQueryAsync(Function.createDelegate(this, this.onItemLoadSuccess), Function.createDelegate(this, this.onFail));
}
}
function onItemLoadSuccess(sender, args){
var glAccount = itemVals.get_item("G_x002f_L_x0020_Account_x0020_nu");
alert(glAccount);
}
function addDetails()
{
acctNo = $('#accntNo').val();
acctDesc = $('#accntDesc').val();
acctJst = $('#accntJust').val();
comment = $('#comment').val();
if(currentUserName=="" || currentUserEmail=="" || acctNo=="")
{
alert("Please fill all the mandatory fields...");
}
else
{
var context = SP.ClientContext.get_current();
context.executeQueryAsync(function(){
var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle("Purchase Requisition");
var newEventCreateInfo = new SP.ListItemCreationInformation();
var newEvent = list.addItem(newEventCreateInfo);
newEvent.set_item("G_x002f_L_x0020_Account_x0020_nu",acctNo);
newEvent.set_item("Account_x0020_Description",acctDesc);
newEvent.set_item("Account_x0020_justification_x002",acctJst);
newEvent.set_item("Comments",comment);
newEvent.set_item("User_x0020_Name",currentUserName);
newEvent.set_item("User_x0020_Email",currentUserEmail);
newEvent.update();
context.executeQueryAsync(function(){alert("Datae has been added successfully...");},function(){alert("Something went wrong!!! Please try again...");})
},
function(sender, args){
alert(args.get_message());
});
}
}
//Get Query string parameters
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
//update Query string values
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
if (uri.indexOf('#') > -1) {
uri = uri.split('#')[0];
uri = uri.replace('#', '');
}
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}