Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: Update Parent record according to child status

$
0
0
Thks for the info..
I tried with few of sample and googling for SPServices..
I was able to succussly change the status from child list by adding content editor web part and in that had button and after click it calls the functions. Manually after clicking on button the code works fine.
here is the code...
<script src="/sites/QualityDev/Style%20Library/js/jquery.min.js" type="text/javascript"></script><script src="/sites/QualityDev/Style%20Library/js/jquery.SPServices-0.5.8.js" type="text/javascript"></script><script type="text/javascript">

// Global variale defined for checking of update to do or not.
var statuscheck = "True" ;
var recfound = "False" ;

function UpdateparentRec()
{
// Get the Query String values and split them out into the vals array
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 childID = vals["ID"];
alert("Child id found is " + childID);

var issueIDRec = [];

$().SPServices({        

    operation: "GetListItems",
    listName: "Time",
    CAMLViewFields: "<ViewFields><FieldRef Name='IssueID' /><FieldRef Name='ID' /></ViewFields>",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Integer'>" + childID + "</Value></Eq></Where></Query>",
    completefunc: function (xData, Status) 
    {               

        $(xData.responseXML).find("[nodeName=z:row]").each(function() 
        {   
            var issueID = $(this).attr("ows_IssueID");
            //alert(issueID) ;

            issueIDRec = issueID.split(";");                
            alert("in UpdateparentRec Function of SPService IssueID is " + issueIDRec[0]);

        });

        //ALERT("CALLING FINDISSUEID") ;
        FindIssueID(issueIDRec[0]);
    }

}); 
}

function FindIssueID(childidRec){
if (!childidRec) {
    alert("FindIssueID(ERROR): No childidRec defined as input param!");
}

$().SPServices({    

    operation: "GetListItems",
    listName: "Time",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='IssueID' /><FieldRef Name='ID' /><FieldRef Name='ReleaseStatus' /></ViewFields>",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='IssueID'/><Value Type='Integer'>" + childidRec + "</Value></Eq></Where></Query>",
    completefunc: function (xData, Status) {                

        $(xData.responseXML).find("[nodeName=z:row]").each(function() 
        {
            recfound = "True" ;

            var title = $(this).attr("ows_Title");                
            alert(title);

            var releasestatus = $(this).attr("ows_ReleaseStatus");
            alert(releasestatus) ;

            if(releasestatus != "Ready to Release")
            {
                statuscheck = "False" ;
            }

         });

        // check if all ready to release and alteast one record found..
        //alert("Release status after loop is " +statuscheck) ;
        //alert("alteast one record found status is " +recfound) ;          
        //alert("in FindIssueID Function IssueID found for parent update is " + childidRec);

        if (statuscheck == "True" && recfound == "True")
        {
              UpdateStatus(childidRec);
        }

    }       
});    
}

function UpdateStatus(itemId){
if (!itemId) {
    alert("UpdateStatus(ERROR): No itemId defined as input param!");
}

$().SPServices({
    operation: "UpdateListItems",
    listName: "Issue",
    ID: itemId,   
    valuepairs: [["CRStatus", "Released"]],    
    completefunc: function (xData, Status){

        alert("Update Done");

    }
});
}</script><input onclick="javascript:UpdateparentRec();" type="button" value="Update parent record!"/>


Now i wanted to have this code updated in save of child list. But some how the code is now working correctly. It doesnot give any error but the flow of logic is irregular.
here is code during edit of child list,. in this too added content editor web part and code below...

<script language="javascript" src="/sites/QualityDev/Style%20Library/js/jquery.min.js" type="text/javascript"></script><script language="javascript" src="/sites/QualityDev/Style%20Library/js/jquery.SPServices-0.5.8.js" type="text/javascript"></script><script language="javascript" type="text/javascript">

// Global variale defined for checking of update to do or not.
var statuscheck = "True" ;
var recfound = "False" ;
var issueIDRec = [];

function PreSaveItem()
{

try{
// do something here...if everthing works fine, return true.     
alert("calling Presaveitem Function" ) ;    
// Get the Query String values and split them out into the vals array
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 childID = vals["ID"];
alert("Child id found is " + childID);  

$().SPServices({        

    operation: "GetListItems",
    listName: "Time",
    CAMLViewFields: "<ViewFields><FieldRef Name='IssueID' /><FieldRef Name='ID' /></ViewFields>",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Integer'>" + childID + "</Value></Eq></Where></Query>",
    completefunc: function (xData, Status) 
    {               

        $(xData.responseXML).find("[nodeName=z:row]").each(function() 
        {   
            var issueID = $(this).attr("ows_IssueID");
            //alert(issueID) ;

            issueIDRec = issueID.split(";");                
            alert("in UpdateparentRec Function of SPService IssueID is " + issueIDRec[0]);

        });

        //ALERT("CALLING FINDISSUEID") ;
        //FindIssueID(issueIDRec[0]);   

    }
}) ;

$().SPServices({    

operation: "GetListItems",
listName: "Time",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='IssueID' /><FieldRef Name='ID' /><FieldRef Name='ReleaseStatus' /></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='IssueID'/><Value Type='Integer'>" + issueIDRec[0] + "</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {                

    $(xData.responseXML).find("[nodeName=z:row]").each(function() 
    {
        recfound = "True" ;

        var title = $(this).attr("ows_Title");                
        alert(title);

        var releasestatus = $(this).attr("ows_ReleaseStatus");
        alert(releasestatus) ;

        if(releasestatus != "Ready to Release")
        {
            statuscheck = "False" ;
        }

    });

        // check if all ready to release and alteast one record found..
        //alert("Release status after loop is " +statuscheck) ;
        //alert("alteast one record found status is " +recfound) ;          
        //alert("in FindIssueID Function IssueID found for parent update is " + issueIDRec[0]);

        if (statuscheck == "True" && recfound == "True")
        {
              UpdateStatus(issueIDRec[0]);
        }

    }       
}); 

return true ;      // continues the form submit button.
}

catch(err){
 alert(err.message) ;
 return false ;   // cancel the form submit button.
}
}

function UpdateStatus(itemId){
if (!itemId) {
    alert("UpdateStatus(ERROR): No itemId defined as input param!");
}

$().SPServices({
    operation: "UpdateListItems",
    listName: "Issue",
    ID: itemId,   
    valuepairs: [["CRStatus", "Released"]],    
    completefunc: function (xData, Status){

        alert("Update Done");

    }
});
}</script>

Can someone pls guilde me which steps i have missed..

Regards,
Deepak

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>