Monday, 30 January 2017

Role Based View in Sharepoint Page

1. Using the below script

<script type="text/javascript" src="/SiteAssets/jquery-1.9.1.min.js"></script>
  <script type="text/javascript">
 
var loginName = "";
var userid = _spPageContextInfo.userId;
groupMembers();

function
groupMembers(){
 var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")/Groups";

    $.ajax({
      dataType: 'text',
      url: requestUri,
      data: '',
      success: function (data) {         
        xmlDoc = $.parseXML( data),
        $xml = $( xmlDoc );
       
        $($xml.find("feed>entry")).each(function(){
            var group=$(this).find("content>m\\:properties>d\\:Title").text();           
            if(group=="Sales Members") //or Use Members Id
            {
                $("a#linkCalender").attr("href", "/Lists/Calendar/salesview.aspx");

            }                
        });              
      },     
      error:  function(){
      alert("Error");
    }
    });
}
  </script>


<a id="linkCalender" href="/Lists/Calendar/calendar.aspx">Click Here</a>

No comments:

Post a comment