Wednesday, 30 September 2015

To Sign in as Different User' in SharePoint 2013

Step 1: Go to the welcome.ascx file in 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES':

Step 2: Add the code below to the welcome.ascx file in whichever place you prefer (i.e., in what order you want the link to appear).
<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" Text="<%$Resources:wss,personalactions_loginasdifferentuser%>" Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>" MenuGroupId="100" Sequence="100"  UseShortId="true" />

Refer Link

Monday, 21 September 2015

Use REST in JSOM

get date length in javascript

var d = new Date();
// var month = d.getMonth() + 1;
//var day = d.getDate();

var month = '';
var day = '';
month = d.getMonth() + 1;
day = d.getDate();
var todaysDay =  (day < 10 ? "0" : "") + day ;
var runningMonth = (month < 10 ? "0" : "") + month ;
   
$(document).ready(function () {
 //  SP.SOD.executeOrDelayUntilScriptLoaded(testfunction());
  SP.SOD.executeFunc('sp.js', 'SP.ClientContext', testfunction());
});
function testfunction() {
 $.ajax({

        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('EmployeeBirthDetails')/Items?$select=Name,GradeCode,EmpNo,Designation,LocationDesc&$filter=CalMonth eq '"+runningMonth +"' and CalDay eq '" + todaysDay + "' &$orderby=GradeCode asc",      

        type: "GET",
        headers: { "accept": "application/json;odata=verbose" },
        success: successHandlerforBDay,
        error: errorHandlerforBDay
    });
}
function successHandlerforBDay(data) {
var name = 'No Birthday Today', exp = '',  url = '#', html = '', href = '', empimage = '', empdesignation = '', emploc = '';
var empNo='';
if (data.d.results)
{
var object = data.d.results;
if(object.length == 0) // Showing "No Birthday Today" message if object.length == 0.
{
html += '<dd><p class="boxTitle">' + name + '</p></dd>';
}
else
{

for(var i = 0; i < object.length; i++)
{
  empNo = object[i].EmpNo;
 if(empNo.length == 6 ) // Birthday will show for those employee which empNo is equal to 6 digit.
 {
  name =object[i].Name;
  emploc = object[i].LocationDesc;

  html += '<dd class="row"><img src="' + empimage + '" alt="Emp Image" width="80px" height="77px" /><div class="text"><h3>' + name + '</h3><p>Location: ' + emploc + '</p></div></dd>';
 }
}
}
}


// Apply marquee if  there are more than 2 birthday
if(object.length > 2)
{
html = '<marquee direction="up" scrollamount="2"  onMouseOver="this.setAttribute(\'scrollamount\', 0, 0);" OnMouseOut="this.setAttribute(\'scrollamount\',2, 0);">' + html + '</marquee>';
}

   // alert(pictureURL);
 $('.bdayUsers').html(html);
}

function errorHandlerforBDay(args,sender) {
    alert('Failed');
}get date length in javascript

Friday, 18 September 2015

B'day web part using jsom/csom

var Birthday = {};

Birthday.displayLimit = 100;

Birthday.context = null;

Birthday.web = null;

Birthday.listName = 'Employees';

Birthday.data = null;

Birthday.init = function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', Birthday.load);
};

Birthday.load = function () {
    Birthday.context = new SP.ClientContext.get_current();
    Birthday.web = Birthday.context.get_web();
    Birthday.getTodaysBday();
};
Birthday.getTodaysBday = function () {
    try {
        //
        var d = new Date();
        var month = d.getMonth() + 1;
        var day = d.getDate();

        var list = Birthday.web.get_lists().getByTitle(Birthday.listName);
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name="CalDay" /><Value Type="Number">' + day + '</Value></Eq><Eq><FieldRef Name="CalMonth" /><Value Type="Number">' + month + '</Value></Eq></And></Where><OrderBy><FieldRef Name="Grade" Ascending="True" /></OrderBy></Query><RowLimit>' + Birthday.displayLimit + '</RowLimit></View>');
        Birthday.data = list.getItems(camlQuery);
        Birthday.context.load(Birthday.data);
        Birthday.excecuteQuery(Birthday.onGetTodaysBday, Birthday.onError);
    }
    catch (err) {
        console.log('Error: ' + err.message);
    }
};
Birthday.onGetTodaysBday = function () {
    var name = 'No Birthday Today', exp = '',  url = '#', html = '', href = '', empimage = '', empdesignation = '', emploc = '';
    var bdayListItemEnumerator = Birthday.data.getEnumerator();
    while (bdayListItemEnumerator.moveNext()) {
        var bdayListItem = bdayListItemEnumerator.get_current();
        bdayId = bdayListItem.get_id();
        bdayListItem.get_item('EmpImage') ? empimage = bdayListItem.get_item('EmpImage') : 1;
        bdayListItem.get_item('Title') ? name = bdayListItem.get_item('Title') : 1;
        bdayListItem.get_item('Designation') ? empdesignation = bdayListItem.get_item('Designation') : 1;
        bdayListItem.get_item('Location') ? emploc = bdayListItem.get_item('Location') : 1;

        //orgListItem.get_item('RelatedURL') ? url = orgListItem.get_item('RelatedURL').get_url() : 1;
        href = L_Menu_BaseUrl + '/Lists/Employee/DispForm.aspx?ID=' + bdayListItem.get_item('ID');

        //html += '<dd class="bdayItem"><div class="bdayImage"><img src="' + empimage + '" alt="Emp Image" /></div><div class="bdayDetails"><div class="empName">' + name + " " + lname + '</div><div class="empdesignation">' + empdesignation + '</div><div class="emploc">Location: ' + emploc + '</div></div></dd>';
        html += '<dd class="row"><img src="' + empimage + '" alt="Emp Image" width="80px" height="77px" /><div class="text"><h3>' + name + '</h3><p>Location: ' + emploc + '</p></div></dd>';
       
    }

    if (!Birthday.data.get_count()) {
        html += '<dd><p class="boxTitle">' + name + '</p></dd>';
    }

 
    if (Birthday.data.get_count() > 2) {
        //var urlpath = "http://" + window.location.host + L_Menu_BaseUrl + "/Style%20Library/Yazaki/js/Birthday/jquery.jcarousellite.js";
        //loadjscssfile(urlpath, "js");
        html = '<marquee direction="up" scrollamount="2"  onMouseOver="this.setAttribute(\'scrollamount\', 0, 0);" OnMouseOut="this.setAttribute(\'scrollamount\', 2, 0);">' + html + '</marquee>';
    }
    $('.bdayUsers').html(html);
};
Birthday.onError = function (sender, args) {
    console.log('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
};
Birthday.excecuteQuery = function (successHandler, errorHandler) {
    Birthday.context.executeQueryAsync(
    Function.createDelegate(this, successHandler),
    Function.createDelegate(this, errorHandler));
};

$(document).ready(function () {
    Birthday.init();
});

Friday, 11 September 2015

Flag logic in jquery

// here I have to get file attachments,  one item may have more then one attached file.
                var len = (AttachmentFiles.attach).length;
                var flag = false;
                var flagAttachment = false;
               for (i = 0; i < len;i++)
                {
                 
                   var url = AttachmentFiles.attach[i].url;
                   var name = AttachmentFiles.attach[i].filename;
                   if (flag == false) {
                        txtHTML += '<tr><td class="fileName">' + fileName + '</td><td class="fileName">' + partName + '</td><td class="fileName">' + VendorName + '</td><td class="fileName">' + createdBy + '</td><td><a href=\'' + url + '\'>' + name + '</a></td></tr>';
                        flag = true;
                    }
                    if (flagAttachment == true)
                    {
                        txtHTML += '<tr><td class="fileName"></td><td class="fileName"></td><td class="fileName"></td><td class="fileName"></td><td><a href=\'' + url + '\'>' + name + '</a></td></tr>';

                    }
                    if(flag==true)
                        flagAttachment=true;
                 
                   
               }
                if (len == 0)
                txtHTML += '<tr><td class="fileName">' + fileName + '</td><td class="fileName">' + partName + '</td><td class="fileName">' + VendorName + '</td><td class="fileName">' + createdBy + '</td><td>No Files Found</td></tr>';
                // $("#attachmentSpn").append(tblRow);
               
               
            });
            var itemCount = $(xData.responseXML).find("rs\\:data, data").attr("ItemCount");
            if (itemCount == 0) {
                txtHTML += '<td colspan="2">No Files found for</td>';

            }
            $("#viewTable").html(txtHTML);