<script src="https://pslightwave.sharepoint.com/sites/Operations/WorkOrders/SiteAssets/jquery-2.1.3.min%20(1).js" type="text/javascript"></script>
<script src="https://pslightwave.sharepoint.com/sites/Operations/WorkOrders/SiteAssets/jquery.SPServices-2014.02.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var id = GetParameterValues('id');
function GetParameterValues(param) {
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < url.length; i++) {
var urlparam = url[i].split('=');
if (urlparam[0] == param) {
return urlparam[1];
}
}
}
if(id!=null || id!="undefined")
{
GetData(id);
autoclick();
}
});
function GetData(id)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+id+ qRight;
$().SPServices({
operation: "GetListItems",
async: false,
listName: "tobeexported Work Order db",
CAMLQuery: query,
completefunc: function(xData, Status)
{
$(xData.responseXML).SPFilterNode("z:row").each(function(){
//alert(xData.responseText);
var orderstatus1=$(this).attr("ows_OrderStatus");
Lookup("OrderStatus" ,orderstatus1 )
var customerid=$(this).attr("ows_CustID");
GetcustomerInfo(customerid);
//alert(customerid);
var assignedto=$(this).attr("ows_AssignedTo");
Getassignedto(assignedto);
var assignedto1=$(this).attr("ows_AssignedTo1");
Getassignedto1(assignedto1);
var equ=$(this).attr("ows_Equipment1");
GetEquip(equ);
var assignedto2=$(this).attr("ows_AssignedTo2");
Getassignedto2(assignedto2);
var issuedto=$(this).attr("ows_IssuedTo");
Getissuedto(issuedto);
var assignedto3=$(this).attr("ows_AssignedTo3");
Getassignedto3(assignedto3);
var type=$(this).attr("ows_WorkOrderType");
GetWorkOrderTypeInfo(type);
var jn=$(this).attr("ows_JobNumber");
Getjobnumber(jn);
var actualmh=$(this).attr("ows_ActualManHours");
$('input[title="ActualManHours"]').val(actualmh);
var won=$(this).attr("ows_num");
$('input[title="WorkOrderNumber"]').val(won);
//alert(won);
//---------------------comments-text area-----//
var comments=$(this).attr("ows_Comments");
var systemDescriptionRTETextArea = $("textarea[Title='Comments']");
//alert($(systemDescriptionRTETextArea).html());
$(systemDescriptionRTETextArea).html(comments);
//alert($(systemDescriptionRTETextArea).html());
var tcomments=$(this).attr("ows_TechnicianComments");
var systemDescriptionRTETextArea = $("textarea[Title='TechnicianComments']");
//alert($(systemDescriptionRTETextArea).html());
$(systemDescriptionRTETextArea).html(tcomments);
//alert($(systemDescriptionRTETextArea).html());
var ospupdate1=$(this).attr("ows_OSPFollowUp");
if(ospupdate1=="0")
{
$('input[title="OSPFollowUp"]').prop('checked', false);
}
else
{
$('input[title="OSPFollowUp"]').prop('checked', "checked");
}
var estimatedmh=$(this).attr("ows_EstimatedManHours");
$('input[title="EstimatedManHours"]').val(estimatedmh);
var gridn=$(this).attr("ows_GridNumber");
$('input[title="GridNumber"]').val(gridn);
var discoverwo=$(this).attr("ows_DiscoveryWorkOrder");
$('input[title="DiscoveryWorkOrder"]').val(discoverwo);
var PhoneNumber1=$(this).attr("ows_PhoneNumber");
$('input[title="PhoneNumber"]').val(PhoneNumber1);
var ProjectManager1=$(this).attr("ows_ProjectManager");
$('input[title="ProjectManager"]').val(ProjectManager1);
var Adress1=$(this).attr("ows_Address");
$('input[title="Address"]').val(Adress1);
var EngineeringContact1=$(this).attr("ows_EngineeringContact");
$('input[title="EngineeringContact"]').val(EngineeringContact1);
var Notes1=$(this).attr("ows_Notes");
$('input[title="Notes"]').val(Notes1);
var name1=$(this).attr("ows_Customer");
$('input[title="Customer"]').val(name1);
//---opened date----//
var thisDate =$(this).attr("ows_OpenDate");
var thisDateT = thisDate.substr(0, 10);
var d= new Date(thisDateT);
var dat=d.getDate();
var mon=d.getMonth()+1;
var year=d.getFullYear()+1;
var todayDate = mon+"/"+dat+"/"+year;
//alert(todayDate);
$("[id$='Opened_x0020_Date_972426a8-00f5-4de9-aeb1-46aa9071d736_$DateTimeFieldDate']").val(todayDate);
//---issued date----//
var issDate =$(this).attr("ows_IssueDate");
var thisDateT = issDate.substr(0, 10);
var d= new Date(thisDateT);
var dat=d.getDate();
var mon=d.getMonth()+1;
var year=d.getFullYear()+1;
var issuedDate = mon+"/"+dat+"/"+year;
$("[id$='IssuedDate_7f432728-dd35-487b-9700-3da9dbdfeacc_$DateTimeFieldDate']").val(issuedDate);
//---Completion date----//
var comDate =$(this).attr("ows_CompletionDate");
var thisDateT =comDate.substr(0, 10);
var d= new Date(thisDateT);
var dat=d.getDate();
var mon=d.getMonth()+1;
var year=d.getFullYear()+1;
var compDate = mon+"/"+dat+"/"+year;
$("[id$='Closed_x0020_Time_x0020_Stamp_e9ee0b02-31ea-4287-989a-4dfc9d6268db_$DateTimeFieldDate']").val(compDate);
//---Scheduled date----//
var asDate =$(this).attr("ows_ScheduledDate");
var thisDateT =asDate.substr(0, 10);
var d= new Date(thisDateT);
var dat=d.getDate();
var mon=d.getMonth()+1;
var year=d.getFullYear()+1;
var acsDate = mon+"/"+dat+"/"+year;
$("[id$='Scheduled_x0020_Date_d629465e-23ca-4550-8d43-d77179b7392d_$DateTimeFieldDate']").val(acsDate);
//--osp up date----//
var ospDate =$(this).attr("ows_OSP_x0020_Update");
//alert(ospDate);
var thisDateT =ospDate.substr(0, 10);
var d= new Date(thisDateT);
var dat=d.getDate();
var mon=d.getMonth()+1;
var year=d.getFullYear()+1;
var ospuDate = mon+"/"+dat+"/"+year;
//alert(ospuDate);
$("[id$='osp_x0020_Update_27dd3c3a-e057-4518-9c5e-1e55e3c5f942_$DateTimeFieldDate']").val(ospuDate);
});
}
});
}
function Lookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
//-------------------------------------------------------------------------------//
function GetcustomerInfo(customerid) {
var qLeft = "<Query><Where><Eq><FieldRef Name='CustID' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+customerid+ qRight;
//alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Customer",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var cid=$(this).attr("ows_ID");
//alert(cid);
cidsetLookup( "CustID", cid)
function cidsetLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//----------------------------------------------------------------//
function Getassignedto(assignedto)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='TechName' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+assignedto+ qRight;
// alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Employees",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var aid=$(this).attr("ows_ID");
assignLookup( "AssignedTo", aid)
function assignLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//---------------------------------------------------------------//
function Getassignedto1(assignedto1)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='TechName' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+assignedto1+ qRight;
//alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Employees",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var zid=$(this).attr("ows_ID");
assig1Lookup( "AssignedTo1", zid)
function assig1Lookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//---------------------------------------------------------------//
function Getjobnumber(jn)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='JobNameNumber' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+jn+ qRight;
// alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Mas90 Job Numbers",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var bid=$(this).attr("ows_ID");
//alert(bid);
jbsetLookup( "JobNumber", bid)
function jbsetLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//--------------------------------------------------------------------//
//-------------------------------------------------------//
function GetWorkOrderTypeInfo(type)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='WOTypeName' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+type+ qRight;
// alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "WorkOrderTypes",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(status);
//alert(xData.responseText);
var oid = $(this).attr("ows_ID");
wotsetLookup( "WorkOrderType", oid)
function wotsetLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//-------------------------------------------------------------------------//
//--------------------------------------------------------------------//
function GetEquip(equ) {
var qLeft = "<Query><Where><Eq><FieldRef Name='Enclosure' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+equ+ qRight;
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Enclosure",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var cid=$(this).attr("ows_ID");
//alert(cid);
setLookup( "Equipment", cid)
function setLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//----------------------------------------------------------------//
function Getassignedto2(assignedto2)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='TechName' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+assignedto2+ qRight;
//alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Employees",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var aid=$(this).attr("ows_ID");
assignLookup( "AssignedTo2", aid)
function assignLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//------------------------------------------------------------------------------------//
function Getassignedto3(assignedto3)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='TechName' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+assignedto3+ qRight;
//alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Employees",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var aid=$(this).attr("ows_ID");
assignLookup( "AssignedTo3", aid)
function assignLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
//---------------------------------------------------------------//
function Getissuedto(issuedto)
{
var qLeft = "<Query><Where><Eq><FieldRef Name='TechName' /><Value Type='Text'>";
var qRight = "</Value></Eq></Where></Query>";
var query = qLeft+issuedto+ qRight;
//alert(query);
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Employees",
CAMLQuery: query,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
//alert(xData.responseText);
var aid=$(this).attr("ows_ID");
assignLookup( "IssuedTo", aid)
function assignLookup( fieldTitle, lookupVal)
{
//alert(fieldTitle);
//alert(lookupVal);
//Set default value for lookups with less that 20 items
if ( $("select[title='" +fieldTitle+ "']").html() != null)
{
//$("select[title='"+ fieldTitle +"']").val(lookupVal);
$("select[title='"+ fieldTitle +"']").val(lookupVal);
}
else
{
//get the hiddent input using the "optHid" attribute of displayed Input
hiddenInput = $("input[title='" +fieldTitle +"']").attr("optHid");
//set value in the hidden input
$("input[id='" +hiddenInput +"']").attr("value",lookupVal)
//get the string of choices from the input element so we can set displayed value
choices = $("input[title='" +fieldTitle +"']").attr("choices");
//turn choices string into an array so we can iterate through it
choiceArray = choices.split("|");
//improve performance by iterating over every other entry (just look at values)
for (index = 1; index < choiceArray.length; index = index + 2)
{
if (choiceArray[index] == lookupVal){
//set the displayed input which is the PREVIOUS entry in array
$("input[title='" +fieldTitle +"']").val(choiceArray[index - 1]);
}
}
}
}
});
}
});
}
function autoclick()
{
// $('input[id*="diidIOSaveItem"]').click()
$('#ctl00_ctl33_g_69d5691e_55ca_4e11_b9e2_9ac858fb8ac4_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem').trigger('click');
}
</script>
Saturday, July 25, 2015
Example for spservices to getlist items; function to autopopulate lookup fileds; set date fields; get id value from url and more....
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment