Sunday 13 July 2014

#JQuery to populate people picker field values from one list to another list:


<script type="text/javascript" src="http://igtewfd3461:33333/sites/rndsite/Style%20Library/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="http://igtewfd3461:33333/sites/rndsite/Style%20Library/jquery.SPServices-0.7.2.min.js"></script>
<script type="text/javascript" src="http://igtewfd3461:33333/sites/rndsite/Style%20Library/jquery.SPServices-2013.01.min.js"></script>
<script language="javascript" type="text/javascript">

var cpycode;
var pytye;

$( document ).ready(function() {
alert("hi");

//fill current logged in user name

var user= $().SPServices.SPGetCurrentUser({fieldName: "Name"});
  alert(user);
$().SPServices.SPFindPeoplePicker({
   peoplePickerDisplayName: "Reportor",
   valueToSet: user,
   checkNames: true
  });


$("select[title=companycode]").change(function() {
     
cpycode = $("select[title='companycode'] option:selected").text();
alert(cpycode);

 });

$("select[title=paymentType]").change(function() {
        alert( "Handler for .change() called." );

pytye = $("select[title='paymentType'] option:selected").text();
alert(pytye);
});

 
        });
function AutoPopulate()
{


var camlqry = "<Query>"+
"<Where>"+
"<And>"+
"<Eq>"+
"<FieldRef Name='country' />"+
"<Value Type='Text'>"+cpycode+"</Value>"+
"</Eq>"+
"<Eq>"+
"<FieldRef Name='year' />"+
"<Value Type='Text'>"+pytye+"</Value>"+
"</Eq>"+
"</And>"+
"</Where>"+
"</Query>";

alert(camlqry);

$().SPServices({
                operation: "GetListItems",
                async: false,
                listName: "Country",


CAMLQuery: camlqry,

             
                completefunc: function (xData, Status) {
itemCount = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");


alert(itemCount);


                    alert(Status);
                    $(xData.responseXML).find("z\\:row").each(function ()
{
                         alert("hello");
if(($(this).attr("ows_firstapprover")!=null))
{
                         var thisFA = ($(this).attr("ows_firstapprover"));
                         thisFA=thisFA.split(";#");
alert(thisFA[1]);
populatePP(thisFA[1],"firstapprover");
}

if(($(this).attr("ows_secondapprover")!=null))
{
                        var thisSA = ($(this).attr("ows_secondapprover"));
thisSA=thisSA.split(";#");
alert(thisSA[1]);
populatePP(thisSA[1],"secondapprover");
}

if(($(this).attr("ows_thirdapprover")!=null))
{
                        var thisTA = ($(this).attr("ows_thirdapprover"));
thisTA=thisTA.split(";#");
alert(thisTA[1]);
populatePP(thisTA[1],"thirdapprover");
}

                     

                     
                     
                    });
                }
            });

}


function populatePP(peoplepicker,PP)
{
alert("inside function");
$().SPServices.SPFindPeoplePicker({
   peoplePickerDisplayName: PP,
   valueToSet: peoplepicker,
   checkNames: true
  });

}
     
     
        </script>

No comments:

Post a Comment

Hide Time from events in Calendar list or webpart Use below code in content edit webpart or by editing list page in SharePoint designer ...