Friday, August 1, 2014

Color Code/replace with images a SharePoint List Column Value in Sharepoint 2013- The outstanding JS link property to the rescue

Wondering how to color code a sharepoint list column based on its value.
You have come to the right page here.. congrats..

Requirement: I have a list called colour code. Now I have a column named Active , which stores Yes or No values.




I need to show ticks for all Yes values and Cross for all No. how will i Do it?


JS Link to the rescue.
1 .Go to your Display Form, open the page in edit mode
2. Now in the webpart properties , go to Miscellaneous tab reference the link to a JS file called Colors.js
Put the following in the JS Link proerty "~sitecollection/style Library/colors.js"

3.  Now just paste the following code in Colors.js  file and upload it to the Style Library of the site.
Note: give  your site collection url in the image tag


(function () {     var statusFieldCtx = {};     statusFieldCtx.Templates = {};     statusFieldCtx.Templates.Fields = {     "Active"://Name of the column for which images needs to be displayed
  {     "View": StatusFieldViewTemplate     }
};     SPClientTemplates.TemplateManager.RegisterTemplateOverrides(     statusFieldCtx     ); })(); function StatusFieldViewTemplate(ctx) {     var _statusValue = ctx.CurrentItem.Active; // Active is the column name    if (_statusValue == 'Yes')     {
        return "<img src=SiteCollectionURL/style%20library/tick.png'/>";         } if (_statusValue == 'No') {     return "<img src= SiteCollectionURL /style%20library/cross.png'/>"; } }


4. that’s it and you are done.. Now just go to the list and refresh your page. See the magic your self:

Friday, April 4, 2014

How to hide the Site Contents link from Quick Launch for all the pages across the sites in sharepoint 2013

If you want this to be done for all the pages in teh site .. you must implement it via the master page ..

This would ensure that it is hidden from all the pages

we are goind to use jquery . Create a js file in teh layouts folder. and paste the following code in it .

$(document).ready(function(){

$('a[href$="/_layouts/15/viewlsts.aspx"]').each(function()

{ $(this).hide(); });

});

Now in the master page please refer to the js file as shown below in the layouts before the close of body tag.

"script type="text/javascript" src="_layouts/15/customjsfile.js"

Tuesday, March 11, 2014

How to get the site collection URL in the masterpage of a SharePoint 2013 site or subsites using Javascript in masterpage

There might be times when you really want to get the URL of the site collection within the master page of sharepoint 2013 sites.

well you can achieve it by using the below javascript line .

Inorder to add script in masterpage , we have to follow the conventional and well known method of the script tag inside the body of HTML.

now within the script tag just copy paste the following function

function getSiteCollectionsURL()

{

var sitecollectionURL = window.location.protocol + "//" + window.location.host +_spPageContextInfo.siteServerRelativeUrl

return sitecollectionURL;

}

the function can be called from anywhere inside the masterpage according to your needs.. it will return the site collection url no matter where you are , ie , whether you are in the subsite or the site collection or the nested subsite.

Thursday, March 6, 2014

Read a list column value using SP services in SharePoint

How can i read  a column value value of a share point list using Jquery and SP services

This can be achieved by the following java script function .

Make sure in your JS page you have refered the jquery and spservices link
//read the tiltle field value of ABC list
function ReadColumnValue()
{

var myvalue=null;
var strViewfields = "<ViewFields><FieldRef Name='Title'/></ViewFields>";
$().SPServices({
webURL: strSiteURL,
            operation: "GetListItems",
            async: false,
            listName: "ABC",

            completefunc: function (xData, Status) {
                $(xData.responseXML).SPFilterNode("z:row").each(function () {
               
if($(this).attr("ows_title")!= undefined)
{

       myvalue=$(this).attr("ows_title");


}
                });
            }

        });



the variable myvalue will containt eh list column value of the tilte field of the AB list




How to make sure if a particular SharePoint Group Exists or Not?

Inorder to know if a particular group exists in sharepoint group collection , just use the following function..

 private bool GroupExists(SPGroupCollection objgroups, string strName)
        {
            const string NAME = "Name";
            bool isGroupExists = false;
            if (string.IsNullOrEmpty(strName) ||

                (strName.Length > 255) ||

                (objgroups == null) ||

                (objgroups.Count == 0))
            {

                isGroupExists = false;
            }

            else
            {
                XDocument doc = XDocument.Parse(objgroups.Xml);
                isGroupExists = doc.Descendants().Where(g => g.Attribute(NAME) != null).Where(g => g.Attribute(NAME).Value.Equals(strName, StringComparison.InvariantCultureIgnoreCase)).Count() > 0;
            }
            return isGroupExists;

        }


The function would return true if the group exists in group collection of sharepoint..


You just have to call the function as shown below :



                SPGroupCollection objSiteGroups = YOURWEBOBJECT.SiteGroups;
                if (GroupExists(objSiteGroups, "YOUR GROUP NAME"))
                {
                   // Do all that you want with the group coz the group does exists
                }
Happy sharepointing :)


Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...