Showing posts with label Jquery. Show all posts
Showing posts with label Jquery. Show all posts

Wednesday, March 17, 2021

How to check whether the current user has edit permission for a particular list using JSOM in SharePoint 2013

 we first need to get the login name of user and pass it to the get_effectiveBasePermissions method.


To ensure that user has edit permission, we will check the SP.PermissionKind.editListItems enum.


SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {

    getCurrentUserPermission();

});



function getCurrentUserPermission()

{    

    var web,clientContext,currentUser,oList,perMask;


    clientContext = new SP.ClientContext.get_current();

    web = clientContext.get_web();

    currentUser = web.get_currentUser();   

    oList = web.get_lists().getByTitle('Test List');

    clientContext.load(oList,'EffectiveBasePermissions');

    clientContext.load(currentUser); 

    clientContext.load(web);           


    clientContext.executeQueryAsync(function(){

        if (oList.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)){

            console.log("user has edit permission");

        }else{

             console.log("user doesn't have edit permission");

        }   

    }, function(sender, args){

        console.log('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());

    });

}

Friday, July 24, 2020

JavaScript : How to Convert UTC Date Time to local/EST Hours using JavaScript?

In this below script, Convert UTC Date Time to local/EST Hours

Convert UTC Date Time to local/EST Hours In SharePoint
In this article , we will use default java-script action

Type 1:

var localTime = new Date();
var localKolkata = moment.tz(localTime, "Asia/Kolkata").format("hh:mm:ss");

Javascript script provide date and time format.

Type 2:

function getLocalTime(i) {
    if (typeof i !== 'number') return;
    var d = new Date();
    var len = d.getTime();
    var offset = d.getTimezoneOffset() * 60000;
    var utcTime = len + offset;
    return new Date(utcTime + 3600000 * i);
}

#sharepoint #javascript #datetime #jquery #convertdatetime

Monday, June 20, 2016

How to get Auto populate dropdown in SharePoint List using SPServices?

In this below script, Auto populate dropdown in SharePoint List using SPServices

Auto populate dropdown in SharePoint List using SPServices

<input type="text" id="txtsearch" onkeyup="binddetails()">
Code:
function binddetails()
{
availableTags = [];

  $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "Keywords",
              CAMLQuery: "<Query><Where><Contains><FieldRef Name='Title' /><Value Type='Text'>"+$("#txtsearch").val()+"</Value></Contains></Where></Query>",
                       CAMLViewFields: "<ViewFields Properties='True' />",
            completefunc: function(xData, Status) {
                var ktop = "";
                $(xData.responseXML).SPFilterNode("z:row").each(function() {
                    var titl = "N/A";
                    if ($(this).attr("ows_Title") != null) {
                       // titl = ;
                        availableTags.push($(this).attr("ows_Title"));
                    }
                    });
                    }
                    });
                       $("#txtsearch").autocomplete({
      source: availableTags
    });
}

Thursday, May 12, 2016

How to get all the td values of a Table in a JavaScript function?

In this below script, get all the td values of a Table in a JavaScript

get all the td values of a Table using JavaScript In SharePoint
Script:

$("#tblemp tbody tr").each(function() {

     
      alert($(this).find("td:last-child").html());
    });

HTML:

<table id="tblemp" class="display" cellspacing="0" width="100%">
        <thead>
           <tr>
              <th></th>
             <th>Name</th>
            <th>Position</th>
            <th>Office</th>
           <th>Age</th>
           <th>Start date</th>
          <th>Salary</th>

    </tr>
</thead>
<tbody>
    <tr>
       <td class="details-control" ></td>      
        <td>Tiger Nixon</td>
        <td>System Architect</td>
        <td>Edinburgh</td>
        <td>61</td>
        <td>2011/04/25</td>
        <td>$320,800</td>


    </td>
    </tr>
 
 
  </tbody>
  </table>

Tuesday, April 26, 2016

Item Adding / Item Added Event Receiver for Document Library

In this below script, Item Adding / Item Added Event Receiver

Item Adding / Item Added Event Receiver In SharePoint
Ways to retrieve data are:

Properties.ListItem[«FieldName »]

Properties.AfterProperties[«FieldName »]

Properties.BeforeProperties[«FieldName »]


we must add the synchronization parameter


 to our xml definition.


<Receiver>
<Name>EventReceiver1ItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>TutoTaxonomy.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
<Synchronization>Synchronous</Synchronization>
</Receiver>
In our code we add an update of the column “test”


public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
properties.ListItem["test"] = "test synchro";
properties.ListItem.Update();
}