Thursday, August 11, 2016

Submit User Details using ECMA script

Hi,

There was requirement i.e.

First user clicks on the checkbox as an indication that content as acceptable

After clicking on the Submit button, user details like employee name, employee id have been fetched using JSON.

After that the same have been inserted into the Sharepoint list

For this I have created list with columns Employee Name, Employee Number as Single line of text

Below is the piece of script that has been written to achieve the same

<script language="ecmascript" type="text/ecmascript">
var userarray = [];
$(function(){
                SP.SOD.executeFunc('sp.js', 'SP.ClientContext', GetCurrentUserDetails);
                $(document).on('change','#chkboxagree',function(){
                                if($(this).is(":checked")) {           
                                                $('#btnsaveuserdetails').removeAttr('disabled');
                                }
                                else{$('#btnsaveuserdetails').attr('disabled' , 'disabled');}       
                });
               
                $('#suiteBar').hide();
                var hidechek = $('input[type="checkbox"]');      

                window.onbeforeprint = hidechek.hide();
});

var userid = _spPageContextInfo.userId;
function GetCurrentUserDetails() {
                var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
                var requestHeaders = { "accept" : "application/json;odata=verbose" };

                $.ajax({
                  url : requestUri,
                  contentType : "application/json;odata=verbose",
                  headers : requestHeaders,
                  success : onSuccess,
                  error : onError
                });
}

function onSuccess(data, request){ 
                var loginName = data.d.LoginName.split('|')[1];
                loginName=loginName.replace("mindtree\\","")
                loginName=loginName.toUpperCase();
                $('.lblMID').text(loginName);

                displayname = data.d.Title;

                userarray.push(displayname);
                userarray.push(loginName);

                var currentDate = new Date();
                var day = currentDate.getDate();
                var month = currentDate.getMonth() + 1;
                var year = currentDate.getFullYear();
                document.getElementById('lblsignaturedate').innerHTML = day + "/" + month + "/" + year;
}

function onError(error) {
  alert(error);
}

function SaveUserDetails(){                       
                $('#chkboxagree').attr('disabled' , 'disabled');                    
                var clientContext = SP.ClientContext.get_current();
                var oList = clientContext.get_web().get_lists().getByTitle('listname');
                               
                var itemCreateInfo = new SP.ListItemCreationInformation();
                this.oListItem = oList.addItem(itemCreateInfo);
                oListItem.set_item('EmployeeName', userarray[0]);
                oListItem.set_item('EmployeeMID', userarray[1]);
                oListItem.update();
                clientContext.load(oListItem);
                $("#successmsg").css("display","block");
                document.getElementById('successmsg').innerHTML=userarray[0]+'('+userarray[1]+')'+' HAVE READ THE ABOVE INFORMATION AND ACCEPTED THE SAME';
                clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
                $('#btnsaveuserdetails').attr('disabled' , 'disabled');
                var empName= $('.lblcurrentusername').text(displayname);
}
function onQueryFailed(sender, args) {
}

function printDiv(divName) { 
                var printContents = document.getElementById(divName).innerHTML;
                document.body.innerHTML = printContents;  
                 var printdivdata=window.open('','_blank');
               
                 printdivdata.document.write(printContents);
                printdivdata.document.close();
                printdivdata.focus();
                printdivdata.print();
                printdivdata.close();
}
</script>
<div id="transportladycontent">
<div class="cabdetails">
<br/><br/><br/>
<h1>header</h1><br/>
  <p>Effective date: 01, January 2013</p><br/>
</div>
<b><u>text</u></b><br/><br/>
<b><h3> header:</h3><br/></b>
<b><h3>Header </h3><br/></b>
<ul class="list">
<li>text.</li><br/>
<li> text </li><br/>
<li> text </li><br/>
<li> text  </li><br/>
<li>I text </li><br/>
<li> text.</li></ul>
<br/>
<div class="no-print">
<label for="chkboxagree"><input type="checkbox" id="chkboxagree"> I accept that I have read the above information and understood the same.</label><br/><br/>
</div>
<div class="userdata" style="display:none">
                <p class="sig"><br/>Signature of the Employee<br/><br/><br/><br/></p>
                <p class="name">Name : <span class="lblcurrentusername shw"></span></p>
                <p class="eid">Employee ID : <span class="lblMID shw"></span></p>
                <p class="dat">Date : <span id="lblsignaturedate"></span></p>
</div>
<!--<p class="mesg" id="lbluserdetails"></p>-->
</div>
<div class="footerbtns">
<input type="button" id="btnsaveuserdetails" value="Submit" class="btn save-btn" onclick="SaveUserDetails()" disabled="disabled">
</div>
<p><b><label id="successmsg" value="" style="display:none"></b></p>
<style type="text/css">
@media screen {
                #transportladycontent .cabdetails, .empsign, .sig, .dat{display: none;}
                .userdata span{display: inline;}
                .footerbtns{float:right;}
                .footerbtns .btn{display:inline-block;margin:0 0 0 10px;}
                #transportladycontent ul{list-style:disc}
                #transportladycontent ul li{margin:0 0 0 20px;}
                .ms-rtestate-field h3{float:none;}
                .userdata p span{padding:0 0 0 5px;font-family:open_sanssemibold;}
                .userdata p{margin:0 0 4px;}
                .sig,.name,.eid,.dat{line-height:25px;}
                input[type=button].save-btn {color: #fff;padding: 8px 20px;border: 0;font: 15px 'open_sansbold',Arial, Helvetica, sans-serif;cursor: pointer;width: auto;margin-top: 15px;}
                .save-btn:disabled {opacity: .45;cursor: not-allowed !important;}
                input{display:inline-block!important;}
                #konnectHdr .konnect-head,.knct-ppl-hb{background:none;}
                .konnect-hdr{background:url(/_layouts/15/PeopleHub/images/green_stripes.png) repeat scroll 0 0;}
}
@media print {
                * {display: none;margin: 0;
                padding: 0;
                font-size: 9.5pt}
                body {display: none; }
                h1{padding:50px 0 0 0;}
                .cabdetails, .empsign,.sig, .dat{display: none;} 
                #transportladycontent ul li{margin:0 0 10px 20px!important;}
                #transportladycontent ul{list-style-type:disc!important}
                #transportladycontent p{margin: 0px 0px 10px 0px;line-height: 1.2;}
                .shw{display:none;}
                .empsign p{float:right;text-align:right;line-height:15px;}
                .userdata .name,.userdata .eid,.mesg{display:none;}
                .no-print {display:none!important;}            
}
</style>


Finally has been achieved as below

Friday, August 5, 2016

People Picker Not Loading Post Page Refresh

Hi,

I am using sppeoplepicker.min.js to load people picker on the page.
Noticed a serious issue i.e.

After refreshing the page, people picker was not loading the page.

After clearing the browser cache ,it was loading.

Root cause of the issue has been found i.e.

In the browser,it has been noticed that

It is creating entries ClientPeoplePickerMRU, SPSuiteLinksJson by entering local storage in console of the browser


After page refresh,it was checking for the above entry and it was not loading.

Fix
Now we have removed the entries from the local storage through java script on the page load

Limitations of SharePoint 2013 Designer

i All,

Here I just want to take an opportunity to explain about the limitations of SharePoint 2013 designer that I came across while working with certain task.

Basically I want to add a data view web part to the page for parameters ,apply the filter to the same.

Then hunting started i.e.

·         Felt disappointed to notice that there is no split view in SharePoint 2013 designer which is developer friendly that exists in SharePoint 2010 as below.

·         Created the page under Pages library that has been created through summary links page layout as below
·         Opened the page through SharePoint 2013 designer where I wasn’t able find the parameters option post clicking on the XsltViewWebpart tag
·         Through developer goddess “Google Maatha” came to know that web part page is better to add DataViewWebPart through SharePoint 2013 Designer.
·         So, created web part page which gets created only under ‘SitePages’ folder.
·         After this, noticed that DataViewWebpart is greyed out as below.
·         But again “Google Maatha” has pushed to move ahead through valuable inputs i.e.
·         Changed system master page to seattle master page as below

·         Closed and reopened the Sharepoint 2013 designer where it is recommended to see the updates.
·         Because certain times, after clicking on refresh as well, haven’t noticed the changes.
·         Now, was able to insert DataViewWebpart after placing a cursor in between of ZoneTemplate Tag
·         Able to add the parameters after clicking on XsltViewWebPart tag as below
·         Hope this helps somebody who is working/going to work in SharePoint 2013 DesignerJ.


Saturday, March 12, 2016

JQuery to redirect Non Site Collection administrators to Access Denied Page

Hi,

We had certain security urls.

We want to redirect Non site collection administrators to Access Denied Page instead of accessing secured urls.

For this, we have written the jquery as below

// Start .......Admin Settings JS to....................


/************************* Hide ==============*/
$(document).ready(function () {
    console.log('load');
    //check the current user
    SP.SOD.executeFunc('sp.js''SP.ClientContext', IsCurrentUserWithContributePerms);

});

//Logic to Redirect non site collection admins to Access Denied Page
function IsCurrentUserWithContributePerms() {
    console.log('Hi');
    IsCurrentUserMemberOfGroup(function (isCurrentUserInGroup) {

    });
}

//End of edit form validation script

function IsCurrentUserMemberOfGroup(OnComplete) {
    var context = new SP.ClientContext.get_current();
    var currentWeb = context.get_web();
    var currentUser = context.get_web().get_currentUser();
    context.load(currentUser);
    console.log(currentUser);

    context.executeQueryAsync(
            function (sender, args) {
                var userInGroup = IsUserInGroup(currentUser);
                console.log('S');
                OnComplete(userInGroup);
            },
            function OnFailure(sender, args) {
                console.log('F');
                OnComplete(false);
            }
    );

    function IsUserInGroup(user) {

        var isSiteAdmin = user.get_isSiteAdmin();
        if (isSiteAdmin) {
            console.log('Admin');

            return isSiteAdmin;

        }

        else {
            console.log('URL');

            var url = (window.location.href).toString().toLowerCase();
            console.log(url);
            if (url.indexOf("/_layouts/15/people.aspx") != -1 || url.indexOf("/_layouts/15/viewlsts.aspx") != -1 || url.indexOf("/_layouts/15/recyclebin.aspx") != -1 || url.indexOf("/_catalogs/masterpage/forms/allitems.aspx") != -1 || url.indexOf("/_layouts/15/user.aspx") != -1 || url.indexOf("/_layouts/15/groups.aspx") != -1 || url.indexOf("/_layouts/15/managefeatures.aspx") != -1 || url.indexOf("/_layouts/15/changesitemasterpage.aspx") != -1 || url.indexOf("/_layouts/15/settings.aspx") != -1 || url.indexOf("/_layouts/15/sitemanager.aspx") != -1 || url.indexOf("/_layouts/15/savetmpl.aspx") != -1 || url.indexOf("/_layouts/15/mngsiteadmin.aspx") != -1 || url.indexOf("/_layouts/15/mngsubwebs.aspx") != -1 || url.indexOf("/_layouts/15/sitedirectorysettings.aspx") != -1 || url.indexOf("/_layouts/15/mngctype.aspx") != -1 || url.indexOf("/_layouts/15/adminrecyclebin.aspx") != -1 || url.indexOf("/_layouts/15/areanavigationsettings.aspx") != -1 || url.indexOf("/_layouts/15/user.aspx") != -1 || url.indexOf("/_layouts/spusageweb.aspx") != -1 || url.indexOf("/_layouts/15/subedit.aspx") != -1 || url.indexOf("/_layouts/15/subchoos.aspx") != -1 || url.indexOf("/_catalogs/wt/forms/common.aspx") != -1 || url.indexOf("/_catalogs/wt/forms/allitems.aspx") != -1 || url.indexOf("/_layouts/15/mngfield.aspx") != -1 || url.indexOf("/_catalogs/lt/forms/allitems.aspx") != -1 || url.indexOf("/_catalogs/theme/forms/allitems.aspx") != -1 || url.indexOf("/_catalogs/theme/forms/allitems.aspx") != -1 || url.indexOf("/_catalogs/wp/forms/allitems.aspx") != -1 || url.indexOf("/_catalogs/wp") != -1 || url.indexOf("/_catalogs/solutions/") != -1 || url.indexOf("/_layouts/15/sharepointdesignersettings.aspx") != -1 || url.indexOf("/_layouts/15/areawelcomepage.aspx") != -1 || url.indexOf("/_layouts/15/areatemplatesettings.aspx") != -1 || url.indexOf("?contents=1") != -1 || url.indexOf("?pageview=shared&toolpaneview=2") != -1 || url.indexOf("?toolpaneview=2") != -1 || url.indexOf("_catalogs/users/simple.aspx") != -1 || url.indexOf("/_layouts/15/newsbweb.aspx") != -1 || url.indexOf("/_layouts/15/create.aspx") != -1 || url.indexOf("/_layouts/15/spcf.aspx") != -1 || url.indexOf("/_layouts/15/appregnew.aspx") != -1 || url.indexOf("/_layouts/15/srchvis.aspx") != -1 || url.indexOf("/_layouts/15/spcontnt.aspx") != -1 || url.indexOf("/_layouts/15/role.aspx") != -1 || url.indexOf("/_layouts/15/createpage.aspx") != -1 || url.indexOf("/_layouts/15/sitesubs.aspx") != -1 || url.indexOf("/_layouts/15/prjsetng.aspx") != -1) {
                console.log('REdirectURL');
                window.location.replace(_spPageContextInfo.webAbsoluteUrl + "/_layouts/15/AccessDenied.aspx");
            }
            console.log('Exit');

            return isSiteAdmin;

        }

    }
}


//End

Provided the path in the master page that is being used.
Finally non site collection administrators were getting Access Denied Page as below