Skip to main content

Code To Save the Items in SharePoint Using SP Service : All type of columns

//***********************************************Code Start*****************************************************

$(document).ready(function()
{

//**********Enable/Disable Approval Required By PE field, based on Type of Request selection
$("input:radio[name=ctl00$m$g_0114c063_901b_4b52_ba51_625c6af34065$ff41$ctl00$RadioButtons]").change(function() {
var value = $(this).val();
if (value =="ctl00" || value =="ctl01" )
{
$('input:checkbox[name=ctl00$m$g_0114c063_901b_4b52_ba51_625c6af34065$ff181$ctl00$ctl00$BooleanField]').attr('checked', true);
$("input[title='Approval Required By PE']").removeAttr("disabled");
}
else
{
$('input:checkbox[name=ctl00$m$g_0114c063_901b_4b52_ba51_625c6af34065$ff181$ctl00$ctl00$BooleanField]').attr('checked', false);
$("input[title='Approval Required By PE']").attr("disabled", "disabled");
}
});

$().SPServices.SPFilterDropdown({
  relationshipList: "Program Profile",
  relationshipListColumn: "Title",
  columnName: "Program Title",
  CAMLQuery: "<Eq><FieldRef Name='Genre' /><Value Type='Choice'>Original Series</Value></Eq>",
  completefunc: null,
  debug: false
});

//Clear all auto populated fields
$('select[title="Program Title"]').change(function(e) {
ClearAllPeopleFields();
$("input[Title='Focus ID']").val('');
var selProgramID = $('select[title="Program Title"] :selected').val()
//Filter Episode Drop Down
$().SPServices.SPCascadeDropdowns({
relationshipList: "Episode Profile",
relationshipListParentColumn: "ProgramTitle",
relationshipListChildColumn: "LinkTitle",
parentColumn: "Program Title",
childColumn: "Episode",
debug: true
});
});


//Episode selction change
$('select[title="Episode"]').change(function(e) {
var epid = $('select[title="Episode"] :selected').val();
var ProgId= $('select[title="Program Title"] :selected').val();

ClearAllPeopleFields();

$().SPServices({
       operation: "GetListItems",
       listName: "Episode Profile",
       CAMLViewFields: "<ViewFields>"+
        "<FieldRef Name='AirDate' /><FieldRef Name='Focus_x0020_ID' /><FieldRef Name='MR_x0020_Contact_x0020__x0023_1' /><FieldRef Name='MR_x0020_Contact_x0020__x0023_2' />"+
        "<FieldRef Name='PhotoEditor' /><FieldRef Name='AccountManager' /><FieldRef Name='Ingestor' /><FieldRef Name='Retoucher' /><FieldRef Name='Metadata' />"+
        "</ViewFields>",      
       CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>"+ epid +"</Value></Eq></Where></Query>",
       
       completefunc: function (xData, Status) {
        //alert(Status);
   $(xData.responseXML).SPFilterNode("z:row").each(function() {
//Set Focus ID

//var airdate = $(this).attr("ows_AirDate");
var EAirDate = $(this).attr("ows_AirDate");
$("input[Title='ADate']").val(EAirDate);
//alert(EAirDate);
   var focus = $(this).attr("ows_Focus_x0020_ID");
        if(focus==null)
focus='';
else
focus=Math.round(focus);
   $("input[Title='Focus ID']").val(focus);
 
   var AccountManager= $(this).attr("ows_AccountManager");
if(AccountManager!= null)
{
setpeoplefield("Account Manager",AccountManager);
}
   var retoucher = $(this).attr("ows_Retoucher");
            if(retoucher != null)
            {              
               setpeoplefield("Retoucher",retoucher);
               }
               var PhotoEditor= $(this).attr("ows_PhotoEditor");
               if(PhotoEditor != null)
               {
              setpeoplefield("Photo Editor",PhotoEditor);
}
var Ingestor = $(this).attr("ows_Ingestor");
               if(Ingestor != null)
               {
               setpeoplefield("Ingestor",Ingestor);
               }
               var Metadata= $(this).attr("ows_Metadata");
if(Metadata!= null)
{
setpeoplefield("Metadata",Metadata);
}
               var mrcontact1 =  $(this).attr("ows_MR_x0020_Contact_x0020__x0023_1");
               if(mrcontact1 != null)
               {
setpeoplefield("MR Contact #1",mrcontact1);
               }
             
               var mrcontact2 =  $(this).attr("ows_MR_x0020_Contact_x0020__x0023_2");
               if(mrcontact2 != null)
               {
setpeoplefield("MR Contact #2",mrcontact2);
               }
});
}
});

$().SPServices({
       operation: "GetListItems",
       listName: "Episode Profile",
       CAMLViewFields: "<ViewFields>"+        
"<FieldRef Name='MR_x0020_Contact_x0020__x0023_3' /><FieldRef Name='MR_x0020_Contact_x0020__x0023_4' />"+
"<FieldRef Name='Legal_x0020_Contact_x0020__x0023' /><FieldRef Name='Legal_x0020_Contact_x0020__x00231' /><FieldRef Name='Legal_x0020_Contact_x0020__x00230' /><FieldRef Name='Legal_x0020_Contact_x0020__x00232' />"+
        "</ViewFields>",      
       CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>"+ epid +"</Value></Eq></Where></Query>",
       
       completefunc: function (xData, Status) {
   $(xData.responseXML).SPFilterNode("z:row").each(function() {
   
    //var airdate = $(this).attr("ows_AirDate");
               var mrcontact3 =  $(this).attr("ows_MR_x0020_Contact_x0020__x0023_3");
               if(mrcontact3 != null)
               {
  setpeoplefield("MR Contact #3",mrcontact3);
               }
               
               var mrcontact4 =  $(this).attr("ows_MR_x0020_Contact_x0020__x0023_4");
               if(mrcontact4 != null)
               {
                setpeoplefield("MR Contact #4",mrcontact4);
}

               var legalcontact1= $(this).attr("ows_Legal_x0020_Contact_x0020__x0023");
               if(legalcontact1 != null)
               {
setpeoplefield("Legal Contact #1",legalcontact1);
}
             
               var legalcontact2= $(this).attr("ows_Legal_x0020_Contact_x0020__x00230");
               if(legalcontact2 != null)
               {
                setpeoplefield("Legal Contact #2",legalcontact2);
}

var legalcontact3= $(this).attr("ows_Legal_x0020_Contact_x0020__x00231");
               if(legalcontact3 != null)
               {
setpeoplefield("Legal Contact #3",legalcontact3);
}

var legalcontact4= $(this).attr("ows_Legal_x0020_Contact_x0020__x00232");
if(legalcontact4 != null)
{
setpeoplefield("Legal Contact #4",legalcontact4);
}
});
}
});


// getting contract from program profile list
       $().SPServices({
        operation: "GetListItems",
listName: "Program Profile",
CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Contract1' /><FieldRef Name='Contract2' /><FieldRef Name='Contract3' /><FieldRef Name='Contract4' /></ViewFields>",        
CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>"+ProgId+"</Value></Eq></Where></Query>",

completefunc: function (xData, Status) {          
            $(xData.responseXML).SPFilterNode("z:row").each(function()
            {
            var ProID= $(this).attr("ows_ID");
           
            var contract= $(this).attr("ows_Contract1");
               if(contract!= null)
$("input[Title='Contract1']").val(contract);
           
            var contract2= $(this).attr("ows_Contract2");
            if(contract2!= null)              
            $("input[Title='Contract2']").val(contract2);
           
            var contract3= $(this).attr("ows_Contract3");
            if(contract3!= null)
            $("input[Title='Contract3']").val(contract3);
           
            var contract4= $(this).attr("ows_Contract4");
            if(contract4!= null)
            $("input[Title='Contract4']").val(contract4);
            });
}
});

// getting phtographer from phtographer list

       $().SPServices({
        operation: "GetListItems",
listName: "Episode Profile",        
CAMLViewFields: "<ViewFields><FieldRef Name='Photographer1' /><FieldRef Name='Photographer2' /><FieldRef Name='Photographer3' /><FieldRef Name='Photographer4' /></ViewFields>",        
CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>"+epid+"</Value></Eq></Where></Query>",

completefunc: function (xData, Status) {
         
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
           
                     
            var Photographer1= $(this).attr("ows_Photographer1");
           
       if(Photographer1!= null)
       {
       
        Photographer1=Photographer1.split(';#');
           Photographer1=Photographer1[0];                          
           $('select[title="Photographer1"]').val(Photographer1);
           setPhotographerComments(Photographer1,'Label1');
       }
       var Photographer2= $(this).attr("ows_Photographer2");
       if(Photographer2!= null)
       {
       
        Photographer2=Photographer2.split(';#');
           Photographer2=Photographer2[0];                          
           $('select[title="Photographer2"]').val(Photographer2);
           setPhotographerComments(Photographer2,'Label2');
       }      

       var Photographer3= $(this).attr("ows_Photographer3");
       if(Photographer3!= null)
       {
       
        Photographer3=Photographer3.split(';#');
           Photographer3=Photographer3[0];                          
           $('select[title="Photographer3"]').val(Photographer3);
           setPhotographerComments(Photographer3,'Label3');
       }

       var Photographer4= $(this).attr("ows_Photographer4");
       if(Photographer4!= null)
       {

        Photographer4=Photographer4.split(';#');
           Photographer4=Photographer4[0];                          
           $('select[title="Photographer4"]').val(Photographer4);
           setPhotographerComments(Photographer4,'Label4');
       }
 
            });
}
});
});
});


function ClearAllPeopleFields()
{
var blankValue= " ";
clearpeoplefield("Retoucher",blankValue);
    clearpeoplefield("Ingestor",blankValue);
    clearpeoplefield("MR Contact #1",blankValue);
    clearpeoplefield("MR Contact #2",blankValue);
    clearpeoplefield("MR Contact #3",blankValue);
    clearpeoplefield("MR Contact #4",blankValue);
    clearpeoplefield("Legal Contact #1",blankValue);
    clearpeoplefield("Legal Contact #2",blankValue);
    clearpeoplefield("Legal Contact #3",blankValue);
    clearpeoplefield("Legal Contact #4",blankValue);            
clearpeoplefield("Account Manager",blankValue);            
clearpeoplefield("Metadata",blankValue);            
clearpeoplefield("Photo Editor",blankValue);
}

function clearpeoplefield(fieldName,fieldValue)
{
$().SPFindPeoplePicker({
peoplePickerDisplayName: fieldName,
valueToSet: fieldValue,
checkNames: false
});
}

function setpeoplefield(fieldName,fieldValue)
{
fieldValue=fieldValue.split("#");
fieldValue=fieldValue[1];

$().SPFindPeoplePicker({
peoplePickerDisplayName: fieldName,
valueToSet: fieldValue,
checkNames: true
});
}

function clearAllFields()
{
 
$("input[Title='Contract1']").val('');
$("input[Title='Contract2']").val('');
$("input[Title='Contract3']").val('');
$("input[Title='Contract4']").val('');

//Photographer fields
$('select[title="Photographer1"] :selected').val(0);
$('select[title="Photographer1"] :selected').val(0);
    $('select[title="Photographer1"] :selected').val(0);
    $('select[title="Photographer1"] :selected').val(0);
   
}

function setPhotographerComments(PhotogrpaherID,ControlID)
{
document.getElementById(ControlID).innerHTML = "";
$().SPServices({
operation: "GetListItems",
   listName: "Photographers",
   CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /></ViewFields>",          
   CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>"+PhotogrpaherID+"</Value></Eq></Where></Query>",
   completefunc: function (xData, Status) {
    $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var comments= $(this).attr("ows_Comments");
           if(comments!= null){
            document.getElementById(ControlID).innerHTML = comments;
           }                
});
}
});
}
function validate(strdate)
{
var alertMessage="";
if((($("input[title='Request Title']").val())=="") || (($("input[title='Due Date']").val())=="") || (($(".retoucher div[title='People Picker']").siblings("textarea").val())=="") || ($(".retoucher div[title='People Picker']").length == 0))
{
if(($("input[title='Request Title']").val())=="")
{
alertMessage=alertMessage+"Request Title is required";
}
if(($("input[title='Due Date']").val())=="")
{
alertMessage=alertMessage+"\nDue Date is required"
}
if(($(".retoucher div[title='People Picker']").siblings("textarea").val())=="")
{
alertMessage=alertMessage+"\nRetoucher is required"
}
if($(".typeofrequest input:radio:checked").length == 0)
{
alertMessage=alertMessage+"\nType of Request is required"
}

if(isNaN($("input[title='Focus ID']").val()))
{
alert("Focus ID can only accpet numeric values");
}
alert(alertMessage);
}
else
{
itemsChecked(strdate);
}
}

// function for get episode

function getprgEpiItemID(title,ProID,ProT,Epid,dueDate,instructnnew,legalinstructnnew,typeofrequest,noofimages,status,retoucher,photographer1,photographer2,photographer3,photographer4,Contract1,Contract2,Contract3,Contract4,contract,focus,legalrestric,accountmanager,comments,retoucher,ingestor,metadata,photoeditor,mrcontact1,mrcontact2,mrcontact3,mrcontact4,legalcontact1,legalcontact2,legalcontact3,legalcontact4,approvedcheckbox,RetouchingRequiredcheckbox,airdate)
{

var vals = new Object();
    var qs = location.search.substring(1, location.search.length);
    var args = qs.split("&");
    for (var i=0; i < args.length; i++)
    {
        var nameVal = args[i].split("=");
        var temp = unescape(nameVal[1]).split('+');
        nameVal[1] = temp.join(' ');
        vals[nameVal[0]] = nameVal[1];
    }
    var itemID;
    var parentID,episodeID;  

if(vals["ItemID"]!=null)
{

itemID= vals["ItemID"];
$().SPServices({
        operation: "GetListItems",
        listName: "Image Request Detail",
        CAMLViewFields: "<ViewFields><FieldRef Name='ProgramId' /><FieldRef Name='EpisodeID' /></ViewFields>",
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Integer'>" + itemID + "</Value></Eq></Where></Query>",
        completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() {

            parentID = $(this).attr("ows_ProgramId");
                     
            episodeID = $(this).attr("ows_EpisodeID");
           
           
            //updatelist(title,ProID,dueDate,instructnnew,legalinstructnnew,typeofrequest,noofimages,status,retoucher,photographer1,photographer2,photographer3,photographer4,Contract1,Contract2,Contract3,Contract4,contract,focus,legalrestric,parentID,episodeID,accountmanager,comments,retoucher,ingestor,metadata,photoeditor,mrcontact1,mrcontact2,mrcontact3,mrcontact4,legalcontact1,legalcontact2,legalcontact3,legalcontact4,approvedcheckbox,RetouchingRequiredcheckbox);
            });
           }
         
          });

}
else if(vals["ProgID"]!=null && vals["EpiID"]!=null)
{
parentID = vals["ProgID"];
    episodeID = vals["EpiID"];
    //alert(parentID +episodeID );
    //updatelist(title,ProID,ProT,dueDate,instructnnew,legalinstructnnew,typeofrequest,noofimages,status,retoucher,photographer1,photographer2,photographer3,photographer4,Contract1,Contract2,Contract3,Contract4,contract,focus,legalrestric,parentID,episodeID,accountmanager,comments,retoucher,ingestor,metadata,photoeditor,mrcontact1,mrcontact2,mrcontact3,mrcontact4,legalcontact1,legalcontact2,legalcontact3,legalcontact4,approvedcheckbox,RetouchingRequiredcheckbox);
}
else
{
// code for save the date without query string

   
updatelistitem(title,ProID,dueDate,instructnnew,legalinstructnnew,typeofrequest,noofimages,status,retoucher,photographer1,photographer2,photographer3,photographer4,Contract1,Contract2,Contract3,Contract4,contract,focus,legalrestric,ProT,Epid,accountmanager,comments,retoucher,ingestor,metadata,photoeditor,mrcontact1,mrcontact2,mrcontact3,mrcontact4,legalcontact1,legalcontact2,legalcontact3,legalcontact4,approvedcheckbox,RetouchingRequiredcheckbox,airdate);

}

}


// Function for saving the data in  list

function itemsChecked(strdate)
    {

    var idValues = new Array();

//alert("on items checked");

$(".typeofrequest input:radio:checked").each(function()
{
var typeofrequest= $(this).siblings("label").html();
//alert(typeofrequest);
var title=$("input[title='Request Title']").val();

var ProT=$("select[title='Program Title']").val();

var ProID=$("select[title='Program Title']").val();

var Epid=$("select[title='Episode']").val();


var dueDate=$("input[title='Due Date']").val();
var airdate=$("input[title='ADate']").val();

dueDate=ConvertDateToISO(dueDate);

//var date = new Date(dueDate);
//var instructn=$("input[title='InstructionForRetoucher']").val();
var instructn=$("nobr:contains('PE Instructions')").closest('tr').find("div[role='textbox']").html();

//var instructn= $("div[role='textbox']").html();
var tmp = document.createElement("DIV");
                tmp.innerHTML = instructn;
                    instructnnew = tmp.textContent||tmp.innerText;


var Legalrestrictions=$("nobr:contains('Legal Restrictions')").closest('tr').find("div[role='textbox']").html();

//var instructn= $("div[role='textbox']").html();
var tmp1 = document.createElement("DIV");
                tmp1.innerHTML = Legalrestrictions;
                    legalinstructnnew = tmp1.textContent||tmp1.innerText;
                   
                   
        var stcomments=$("nobr:contains('Comments')").closest('tr').find("div[role='textbox']").html();


var tmp5 = document.createElement("DIV");
                tmp5 .innerHTML = stcomments;
                    comments = tmp5.textContent||tmp5.innerText;          
//alert(comments);

var noofimages=$("input[title='Number Of Images']").val();
//alert(noofimages);
var status=$("select[title='Status']").val();

var accountmanager = getPickerInputElement("ff19");
//alert("accountmanager="+accountmanager);
var retoucher = getPickerInputElement("ff8");
//alert("retoucher ="+retoucher);

var ingestor = getPickerInputElement("ff28");
//alert("ingestor ="+ingestor);
var metadata = getPickerInputElement("ff29");
//alert("metadata ="+metadata);
var mrcontact1 = getPickerInputElement("ff20");
//alert("mrcontact1 ="+mrcontact1);
var mrcontact2= getPickerInputElement("ff21");
//alert("mrcontact2="+mrcontact2);
var mrcontact3= getPickerInputElement("ff22");
//alert("mrcontact3="+mrcontact3);
var mrcontact4= getPickerInputElement("ff23");
//alert("mrcontact4="+mrcontact4);
var legalcontact1 = getPickerInputElement("ff24");
//alert("legalcontact1 ="+legalcontact1);
var legalcontact2 = getPickerInputElement("ff25");
//alert("legalcontact2 ="+legalcontact2);

var legalcontact3 = getPickerInputElement("ff26");
//alert("legalcontact3 ="+legalcontact3);

var legalcontact4 = getPickerInputElement("ff27");

var photoeditor = getPickerInputElement("ff37");

var photographer = $("select[Title='Photographer']").val();
//testing line
var approvedcheckbox;

var RetouchingRequiredcheckbox;
if ($('#ctl00_m_g_0114c063_901b_4b52_ba51_625c6af34065_ff181_ctl00_ctl00_BooleanField').is(':checked'))
{
  approvedcheckbox = 1;
  //alert("true");
}

else
{
  approvedcheckbox = 0;
 
  //alert("false");
}

if ($('#ctl00_m_g_0114c063_901b_4b52_ba51_625c6af34065_ff171_ctl00_ctl00_BooleanField').is(':checked'))
{
  RetouchingRequiredcheckbox = 1;
  //alert("true");
}
else
{
  RetouchingRequiredcheckbox = 0;
 
  //alert("false");
}

//  var dec for et the Photographer fiels value

var photographer1= $("select[Title='Photographer1']").val();
var photographer2 = $("select[Title='Photographer2']").val();
var photographer3 = $("select[Title='Photographer3']").val();
var photographer4 = $("select[Title='Photographer4']").val();

// Code get the Contract  fiels value

var Contract1=$("input[title='Contract1']").val();
var Contract2=$("input[title='Contract2']").val();
var Contract3=$("input[title='Contract3']").val();
var Contract4=$("input[title='Contract4']").val();

        var contract = $("input[Title='Photoshoot/Contract']").val();
       

        var focus = $("input[Title='Focus ID']").val();
        // alert("focus ="+focus);

        var legalrestric=$("nobr:contains('Legal Restrictions')").closest('tr').find("div[role='textbox']").html();
     
        var tmp3 = document.createElement("DIV");
                tmp3.innerHTML = legalrestric;
                   legalrestric = tmp3.textContent||tmp3.innerText;
       //alert('update')
getprgEpiItemID(title,ProID,ProT,Epid,dueDate,instructnnew,legalinstructnnew,typeofrequest,noofimages,status,retoucher,photographer1,photographer2,photographer3,photographer4,Contract1,Contract2,Contract3,Contract4,contract,focus,legalrestric,accountmanager,comments,retoucher,ingestor,metadata,photoeditor,mrcontact1,mrcontact2,mrcontact3,mrcontact4,legalcontact1,legalcontact2,legalcontact3,legalcontact4,approvedcheckbox,RetouchingRequiredcheckbox,airdate);
});
}
 
// function for get the value of control
function getPickerInputElement(identifier)
{
                //This function is used to retrieve the people picker field values
                var tags = document.getElementsByTagName("DIV");
                var retoucher="";
                for (var j=0; j < tags.length; j++)
                {
                var tempString = tags[j].id;
                                if ((tempString.indexOf(identifier) > 0) && (tempString.indexOf("UserField_upLevelDiv") > 0))
                                {
                                                var peoplePickerDivs = tags[j].getElementsByTagName("DIV"),
                                                i,
                                                length = peoplePickerDivs.length,
                                                dataDiv = null,
                                                parser = null,
                                                dataDoc = null;
                                               
                                                for (i = 0; i < length; i = i + 1)
                                                {
                                                                if (peoplePickerDivs[i].id != null)
                                                                {
                                                                                if (peoplePickerDivs[i].id == 'divEntityData')
                                                                                {
                                                                                                entityDataDiv = peoplePickerDivs[i];
                                                                                                dataDiv = entityDataDiv.getElementsByTagName('div')[0];
                               
                                                                                                if (window.DOMParser)
                                                                                                {
                                                                                                                parser = new DOMParser();
                                                                                                                dataDoc = parser.parseFromString(dataDiv.attributes["data"].value, "text/xml");
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                                dataDoc = new ActiveXObject("Microsoft.XMLDOM");
                                                                                                                dataDoc.async = "false";
                                                                                                                dataDoc.loadXML(dataDiv.attributes["data"].value);
                                                                                                }
                                                                                                var userId = getXmlValue(dataDoc, "/ArrayOfDictionaryEntry/DictionaryEntry[./Key = 'SPUserID']/Value");
                                                                                                //var userName = getXmlValue(dataDoc, "/ArrayOfDictionaryEntry/DictionaryEntry[./Key = 'AccountName']/Value");
                                                                                                var userName = entityDataDiv.getAttribute("displaytext");
                                                                                                retoucher += userId + ";#" + userName+";#";     //Gets the usersnames in 'ID;#DisplayName' format which is required in UpdateListItem spservice.                                                                                            
                                                                                }
                                                                }
                                                }
                                }
                }
                return retoucher;
}
// end  
    function getXmlValue(xmlDocument, xpath) {
   // alert("getXmlValue");
var results = null;

if (xmlDocument.evaluate) {
results = xmlDocument.evaluate("/ArrayOfDictionaryEntry/DictionaryEntry[./Key = 'SPUserID']/Value", xmlDocument, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if (results.snapshotLength > 0) {
return results.snapshotItem(0).textContent;
}
} else {
results = xmlDocument.selectSingleNode(xpath);
if (results != null) {
return results.text;
}
}

return null;
}

function getPeoplePickerDataDocument() {
//alert("getPeoplePickerDataDocument");
var peoplePickerElement = document.getElementById('ctl00_m_g_f16d3211_6c5d_48a0_8c13_0baec8fc5d63_ff81_ctl00_ctl00_UserField_upLevelDiv'),
peoplePickerDivs = peoplePickerElement.getElementsByTagName('div'),
i,
length = peoplePickerDivs.length,

dataDiv = null,
parser = null,
dataDoc = null;

for (i = 0; i < length; i = i + 1) {
if (peoplePickerDivs[i].id != null) {
if (peoplePickerDivs[i].id == 'divEntityData') {
entityDataDiv = peoplePickerDivs[i];
dataDiv = entityDataDiv.getElementsByTagName('div')[0];

if (window.DOMParser) {
parser = new DOMParser();
dataDoc = parser.parseFromString(dataDiv.attributes["data"].value, "text/xml");
} else {
dataDoc = new ActiveXObject("Microsoft.XMLDOM");
dataDoc.async = "false";
dataDoc.loadXML(dataDiv.attributes["data"].value);
}

return dataDoc;
}
}
}

return null;
}

   
function ConvertDateToISO(dtDate)
{
//*************************************************
//Converts Javascript dtDate to ISO 8601 standard for compatibility with SharePoint lists
//Inputs: dtDate = Javascript date format (optional)
//*************************************************
//alert("InISOCOnversion");
  var d;
  if (dtDate != null)  {
     //Date value supplied
   
     d = new Date(dtDate);
  }
  else  {
     //No date supplied, Create new date object
     d = new Date();
  }
  //Generate ISO 8601 date/time formatted string
  var s = "";
  //alert(d.getFullYear());
  if(d.getFullYear)
  {
  //alert("FullYear");
         s += d.getFullYear() + "-";
    }
    else
    {
    //alert("getyear");
    var year= d.getYear() + 1900;
    s += year + "-";
       
    }
  //s += d.getYear() + "-";
  s += d.getMonth() + 1 + "-";
  s += d.getDate();
  s += "T" + d.getHours() + ":";
  s += d.getMinutes() + ":";
  //Replace the "Z" below with the required
  //time zone offset (eg "+10:00" - Australian EST)
  s += d.getSeconds() + "Z";
  //Return the ISO8601 date string
  return s;
}

function updatelistitem(title,ProID,dueDate,instructnnew,legalinstructnnew,typeofrequest,noofimages,status,retoucher,photographer1,photographer2,photographer3,photographer4,Contract1,Contract2,Contract3,Contract4,contract,focus,legalrestric,parentID,episodeID,accountmanager,comments,retoucher,ingestor,metadata,photoeditor,mrcontact1,mrcontact2,mrcontact3,mrcontact4,legalcontact1,legalcontact2,legalcontact3,legalcontact4,approvedcheckbox,RetouchingRequiredcheckbox,airdate)
{
 

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "Image Request Detail",      

        updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
                    "<Method ID='1' Cmd='New'>" +
                        "<Field Name='Title'>" + CDATAWrap(title) + "</Field>" +
                        "<Field Name='ProgramId'>" + CDATAWrap(ProID) + "</Field>" +
                         "<Field Name='DueDate'>" + CDATAWrap(dueDate) + "</Field>" +
                         "<Field Name='InstructionForRetoucher'>" + CDATAWrap(instructnnew) + "</Field>" +
                        // "<Field Name='LegalRestrictions'>" + CDATAWrap(legalinstructnnew) + "</Field>" +
"<Field Name='TypeOfRequest'>" + CDATAWrap(typeofrequest) + "</Field>" +
"<Field Name='NumberOfImages'>" + CDATAWrap(noofimages) + "</Field>" +
"<Field Name='Status'>" + CDATAWrap(status) +  "</Field>" +
"<Field Name='Retoucher'>" + CDATAWrap(retoucher) +  "</Field>" +
"<Field Name='CopyTypeOfRequest'>" + typeofrequest +  "</Field>" +

"<Field Name='Photographer1'>" + CDATAWrap(photographer1) +  "</Field>" +
"<Field Name='Photographer2'>" + CDATAWrap(photographer2) +  "</Field>" +
"<Field Name='Photographer3'>" + CDATAWrap(photographer3) +  "</Field>" +
"<Field Name='Photographer4'>" + CDATAWrap(photographer4) +  "</Field>" +

"<Field Name='Contract1'>" + CDATAWrap(Contract1) +  "</Field>" +
"<Field Name='Contract2'>" + CDATAWrap(Contract2) +  "</Field>" +
"<Field Name='Contract3'>" + CDATAWrap(Contract3) +  "</Field>" +
"<Field Name='Contract4'>" + CDATAWrap(Contract4) +  "</Field>" +


//"<Field Name='ProgramId'>" + CDATAWrap(parentID) +  "</Field>" +
"<Field Name='ProgramTitle'>" + CDATAWrap(parentID) +  "</Field>" +

"<Field Name='EpisodeID'>" + CDATAWrap(episodeID) +  "</Field>" +
"<Field Name='Episode'>" + CDATAWrap(episodeID) +  "</Field>" +
// "<Field Name='PhotoshootContract'>" + CDATAWrap(contract) +  "</Field>" +
"<Field Name='FocusID'>" + CDATAWrap(focus) +  "</Field>" +
"<Field Name='LegalRestrictions'>" + CDATAWrap(legalrestric) +  "</Field>" +
"<Field Name='AccountManager'>" + CDATAWrap(accountmanager) +  "</Field>" +
"<Field Name='Comments'>" + CDATAWrap(comments) +  "</Field>" +
"<Field Name='Ingestor'>" + CDATAWrap(ingestor) +  "</Field>" +
"<Field Name='Metadata'>" + CDATAWrap(metadata) +  "</Field>" +
"<Field Name='PhotoEditor'>" + CDATAWrap(photoeditor) +  "</Field>" +
"<Field Name='MRContact_x0023_1'>" + CDATAWrap(mrcontact1) +  "</Field>" +

"<Field Name='MRContact_x0023_2'>" + CDATAWrap(mrcontact2) +  "</Field>" +
"<Field Name='MRContact_x0023_3'>" + CDATAWrap(mrcontact3) +  "</Field>" +
"<Field Name='MRContact_x0023_4'>" + CDATAWrap(mrcontact4) +  "</Field>" +
"<Field Name='LegalContact_x0023_1'>" + CDATAWrap(legalcontact1) +  "</Field>" +
"<Field Name='LegalContact_x0023_2'>" + CDATAWrap(legalcontact2) +  "</Field>" +
"<Field Name='LegalContact_x0023_3'>" + CDATAWrap(legalcontact3) +  "</Field>" +
"<Field Name='LegalContact_x0023_4'>" + CDATAWrap(legalcontact4) +  "</Field>" +
"<Field Name='ApprovalRequiredByPE'>" + CDATAWrap(approvedcheckbox) +  "</Field>" +
"<Field Name='NoRetouchingRequired'>" + CDATAWrap(RetouchingRequiredcheckbox) +  "</Field>" +
"<Field Name='ADate'>" + CDATAWrap(airdate) +  "</Field>" +


                    "</Method>" +
                "</Batch>",
        completefunc: function (xData, Status) {
            //get the ID for the newly created Issue
            var out = $().SPServices.SPDebugXMLHttpResult({
node: xData.responseXML
});

            var newId =  $(xData.responseXML).SPFilterNode("z:row").attr("ows_ID");
         
        }
     
    });
alert("Request Created Successfully");
//$( "#dialog" ).dialog();
window.location.href = '/sites/photoservices/SitePages/Photoeditorjobqueue_Home.aspx';

//ScriptManager.RegisterStartupScript(Page, Page.GetType(), "MessageThenRedirect", "alert('" + "Item created successfully!" + "');window.location='" + "/sites/photoservices/SitePages/Photoeditorjobqueue_Home.aspx",true);

    }

function CDATAWrap(data)
{
return "<![CDATA[" + data + "]]>";
}


// Function for getting commnets on page load  from Photographer lis
$(document).ready(function() {

// Photographer #1
$('select[title="Photographer1"]').change(function(e) {
var selectedValue = $('select[title="Photographer1"] :selected').text();

$().SPServices({
       operation: "GetListItems",
       listName: "Photographers",
       CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /></ViewFields>",
           
       CAMLQuery: "<Query><Where><Eq><FieldRef Name='Name'/><Value Type='Text'>"+selectedValue+"</Value></Eq></Where></Query>",
       completefunc: function (xData, Status) {
        //alert(Status);
           $(xData.responseXML).SPFilterNode("z:row").each(function() {
            //PremiereDate = $(this).attr("ows_PremiereDate");

               var comments= $(this).attr("ows_Comments");
               if(comments!= null)
            {              
             document.getElementById('Label1').innerHTML = comments;
               }
               else
               {
                document.getElementById('Label1').innerHTML = "";
               }

               
});
 }
});
});
//2nd Photographer
$('select[title="Photographer2"]').change(function(e) {
var ph2= $('select[title="Photographer2"] :selected').text();

$().SPServices({
       operation: "GetListItems",
       listName: "Photographers",
       CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /></ViewFields>",
           
       CAMLQuery: "<Query><Where><Eq><FieldRef Name='Name'/><Value Type='Text'>"+ph2+"</Value></Eq></Where></Query>",
       completefunc: function (xData, Status) {
        //alert(Status);
           $(xData.responseXML).SPFilterNode("z:row").each(function() {
            //PremiereDate = $(this).attr("ows_PremiereDate");

               var comments2= $(this).attr("ows_Comments");
               if(comments2!= null)
            {              
             document.getElementById('Label2').innerHTML = comments2;
               }
               else
               {
                document.getElementById('Label2').innerHTML = "";
               }

               
});
 }
});
});

//3rd Photographer
$('select[title="Photographer3"]').change(function(e) {
var ph3= $('select[title="Photographer3"] :selected').text();

$().SPServices({
       operation: "GetListItems",
       listName: "Photographers",
       CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /></ViewFields>",
           
       CAMLQuery: "<Query><Where><Eq><FieldRef Name='Name'/><Value Type='Text'>"+ph3+"</Value></Eq></Where></Query>",
       completefunc: function (xData, Status) {
        //alert(Status);
           $(xData.responseXML).SPFilterNode("z:row").each(function() {
            //PremiereDate = $(this).attr("ows_PremiereDate");

               var comments3= $(this).attr("ows_Comments");
               if(comments3!= null)
            {              
             document.getElementById('Label3').innerHTML = comments3;
               }
               else
               {
                document.getElementById('Label3').innerHTML = "";
               }

               
});
}
});

});
//Photographer
//4rd Photographer
$('select[title="Photographer4"]').change(function(e) {
var ph4= $('select[title="Photographer4"] :selected').text();

$().SPServices({
       operation: "GetListItems",
       listName: "Photographers",
       CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /></ViewFields>",
           
       CAMLQuery: "<Query><Where><Eq><FieldRef Name='Name'/><Value Type='Text'>"+ph4+"</Value></Eq></Where></Query>",
       completefunc: function (xData, Status) {
        //alert(Status);
           $(xData.responseXML).SPFilterNode("z:row").each(function() {
            //PremiereDate = $(this).attr("ows_PremiereDate");

               var comments4= $(this).attr("ows_Comments");
               if(comments4!= null)
            {              
             document.getElementById('Label4').innerHTML = comments4;
               }
               else
               {
                document.getElementById('Label4').innerHTML = "";
               }

               
});
}
});

});
});



// comments hide show
$(document).ready(function(){
/* Hide/Show Editable 'Comments' column based on the 'Status' on page load*/
/* .hiddencolumn is used for editable 'Comments' field & .displayedcolumn is used for displayed 'Comments' field */

if(($("select[title='Status']").val() == 'Approved') || ($("select[title='Status']").val() == 'Rejected'))
{
$('.hiddencolumn').show();
$('.displayedcolumn').hide();


}

/* Hide/Show Editable 'Comments' column based on the 'Status' selected */
$("select[title='Status']").change(function(){
if(($("select[title='Status']").val() == 'Approved') || ($("select[title='Status']").val() == 'Rejected'))
{
// If 'Retouching Approved' or 'Retouching Rejected' is selected, then display editable 'Comments' and hide noneditable 'Comments'
$(".hiddencolumn").show();
$('.displayedcolumn').hide();



}
else
{
// if the above two status's are not selected, then display only non-editable 'Comments' column
$(".hiddencolumn").hide(); // Hide editable 'Comments' field
$(".hiddencolumn div[role='textbox'] p").html(""); // empty the editable 'Comments' field. Because, otherwise, if anyone of the above two status are selected again then earlier entered 'Comments' will be displayed
$('.displayedcolumn').show(); // show the non-editable content


}
});

});

// Popup window code
function newPopup(url){
popupWindow = window.open(
url,'popUpWindow','height=500,width=800,left=50,top=30,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
//*****************************************************Code END****************************************************

Comments

Popular posts from this blog

SharePoint Framework extensions to Call Azure Function

In this article, we will talk about prerequisites, how to call Azure Function from SPFX extension, How to Create HHTP function, connect Visual Styuid editor to Azure and publish them, and Set Up CORS on the Azure Function, Create SharePoint Framework Extension, Azure Function, etc. Prerequisites :  Azure Subscriptions   VS code  Spfx Development Env  -   Step by steps details: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-development-environment  Follow the below steps to create Azure Functions in the Azure portal.  Steps by steps guide:  https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient-enterpriseapi    Reference :  https://docs.microsoft.com/en-us/answers/questions/430645/how-to-access-sharepoint-rest-api-in-my-function-a.html Step-1 : Login to Azure Portal (https://portal.azure.com/)   Step-2 : As highlighted below, click on the  + Create a resource, and click on “Compute”. Now, choose the “Function App”.   Or, for the same Option, you can sea

Build and Deploy a custom theme in SharePoint 2019: Using C# and Site features

Custom Theme and Branding are common to use cases and all kinds of business users like to have the personalized team and collaboration sites. today I am posting C# code that will help to build custom features for SharePoint 2019 site.   If need any assistance, I would be happy to help: kamal_pandey@outlook.com  ----------------------------- Code to build  custom features---------- using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; namespace SharePointBranding.Code {     public class BrandingManager     {         public SPWeb Web { get; set; }         public BrandingManager(SPWeb web)         {             Web = web;         }         public void SetMasterPage(string masterPageUrl, string logoUrl)         {             masterPageUrl = GetMasterPageServerRelativeUrl(masterPageUrl);             Web.MasterUrl = masterPageUrl;