Wednesday, 8 October 2014

How we can write exception errors in SharePoint Default logs..


SharePoint default logs, you can find under 14 hive /logs folder.

private void WriteToSPLog(string source, TraceSeverity traceSeverity, EventSeverity eventSeverity, string message)
        {
            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(source, traceSeverity, eventSeverity), traceSeverity, message, null);


        }


And this is how I called this function:

WriteToSPLog("MyR&D APP" , TraceSeverity.High , EventSeverity.Error , error);

Happy Coding!

Wednesday, 3 September 2014

#Script Editor Web-Part in #SharePoint 2013:


Script editor web-part is nothing but the content editor web-part of SharePoint 2010 or Moss 2007. If you are not aware of CEWP then here is the description for you..

If you want to add any custom javascript code or Html or Jquery code to your pages, you should use this web-part. Here are the steps to achieve this...

How to add script-editor web-part to your site or pages:
  • Log into SharePoint 2013 and click the Page tab from the Ribbon. From here, click on the Setting icon on the upper right and select Edit Page.

  • On the Edit page, select the Insert Web Part tab from the Ribbon. From the Categories menu, select Media and Content and then Script Editor from the Parts menu.

  • Click on the Add button at the bottom of the page to install the Web Part
  • Once the Web Part has been successfully installed on your page, you will see a hyperlink button under the Script Editor labeled EDIT SNIPPET. Click the EDIT SNIPPET link to insert HTML/Script code

  • After you have inputted the appropriate code in the Embed dialog box, click Insert to save the HTML/Script
  • Click the Save button on the right corner of your site.

Hope this helps you guys...

Wednesday, 6 August 2014

Show/Hide #SharePoint columns in a List based on selected values in a drop-down list:


<script language="javascript" type="text/javascript">
$(document).ready(function() {
    showhide();
   $("select[title='FieldName']").change(function() { showhide(); });

});

function showhide()
{
   alert("inside function");// just to debug script , remove while move in production
    var thisVal =  $("select[title='FieldName']").val();
    alert(thisVal);// just to debug script , remove while move in production
    if (thisVal=="Somevalue")// your condition
    {
    alert("show all");// just to debug script , remove while move in production
     $('nobr:contains("FieldName")').closest('tr').show();


}
else
      {
     alert("inside else");// just to debug script , remove while move in production
     $('nobr:contains("FieldName")').closest('tr').hide();

}
</script>

Simple #JQuery to validate any column or field value in SharePoint:



<script src="/sites/rndsite/Style%20Library/jquery-1.8.1.js" type="text/javascript">  </script>
  <script type="text/javascript">
     function PreSaveAction() {
alert('hi');// just to debug script , remove while move in production
alert($("select[title='Fieldname']").val()));
           if($("select[title='Fieldname']").val() ==' ')          {
          alert('Serial number field is Empty: Please enter some value');// just to debug script, remove while move in production
          return false;
          }
            }
    </script>

Tuesday, 15 July 2014

#Datasheet View not working on #SharePoint 2010:


Recently I was struggling with Datasheet View, it was not working in SharePoint 2010 list for some reasons... 

The icon was enabled, but kept receiving the following message:


After struggling for a while I found that I was having Office 2010 x64 with IE x32 on my system. 
That means the datasheet view components weren't installed correctly. I need the x86 version of the components. In my case, I couldn't install  Microsoft Office Access database engine 2010 x86 version, as I have Office 2010 x64. So the option now is to have Microsoft Office Access database engine 2007 x86 instead.

If that is your case follow the link http://www.microsoft.com/en-us/download/confirmation.aspx?id=23734 pick the version suited to your IE version, install it and it should work.

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>

#JQuery to populate the name of current logged in user to a column in a SharePoint list:


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


$(document).ready(function() {
alert("Hi");// this is only for testing
var user= $().SPServices.SPGetCurrentUser({fieldName: "Name"});
  alert(user);// this is only for testing
$().SPServices.SPFindPeoplePicker({
   peoplePickerDisplayName: "firstapprover",
   valueToSet: user,
   checkNames: true
  });
alert("hello india");// this is only for testing
});</script>

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