Tuesday, December 27, 2016

Get the selected item's ID in 2 steps on AllItems.aspx or any view page.

Step 1 - Include SP Services in your javascript file.

<script type="text/javascript" src="../../SiteAssets/jquery.SPServices-2014.02.min.js"></script>

Step 2 -

        var clientContext = SP.ClientContext.get_current();
        var website = clientContext.get_web();
        clientContext.load(website);
        var items = SP.ListOperation.Selection.getSelectedItems(clientContext);
        var k;
        var idList = new Array();
        for (k in items) {
        var  thisID = items[k].id;
          }

Here , "thisID" will give you the selected item's ID on the View.

Call a function on click of a button in SharePoint Ribbon.

To call a JavaScript function from any Custom Action in SharePoint Designer, call the desired 
function in "Navigate To Url" option,




Further, add this function in your JavaScript file which you should include on the page where this custom action will be deployed using Content Editor Web Part.

How to get the List item Id in javascript while in the display form or edit form

You can do this with javascript and JSRequest.
The ID is passed in via the URL, (ie. 'DispForme.aspx?Id=11'), then use the below code to retrieve the '11'..
JSRequest.EnsureSetup(); 
var itemId = JSRequest.QueryString["ID"];

Creating a Custom Action using SharePoint Designer

Step 1 – SharePoint Designer

In SharePoint Designer, open the site containing the library or list where the custom action will be deployed.

From the ribbon, Choose "Custom Actions" and click "View Ribbon"

Create Custom Action as shown below,


Monday, December 26, 2016

Create a JQuery Template in SharePoint

Script File :-

<script src="../../SiteAssets/jquery.tmpl.js"></script>

function CreateJqueryTemplate()
{
     $(".hideThead").show();
    $("#itemList tbody").children().remove();
    items.push({
          Link: url,
 Department: upgdept,
 Confirmed: confirmedStatus,
 Answered: approvedStatus,
 Unanswered: pendingStatus,
 UPGLink: upg
        });
    $( "#itemTemplate" ).tmpl( items ).appendTo( "#itemList tbody" );
}

<script id="itemTemplate" type="text/x-jquery-tmpl">
<tr>
  <td style="background-color:#E6E6E6"><a target="_blank" href="${Link}">Resp_Main_Link : ${Department}</a></td>
  <td style="background-color:#E6E6E6">${Confirmed}</td>
  <td style="background-color:#E6E6E6">${Answered}</td>
  <td style="background-color:#E6E6E6">${Unanswered}</td>
</tr></script>

Aspx File :-

<tr>
<td width="100%">
<table id="itemList" border="1" style="border-collapse:collapse" width="100%">
<thead class="hideThead"><tr>
<td width="25%" align="center" style="background-color:#0078ae;color:white"><b>Target Department</b></td>
<td width="25%" align="center" style="background-color:#0078ae;color:white"><b>Confirmed</b></td>
<td width="25%" align="center" style="background-color:#0078ae;color:white"><b>Answered</b></td>
<td width="25%" align="center" style="background-color:#0078ae;color:white"><b>Unanswered</b></td>
</tr></thead>
<tbody></tbody></table>
 </td>
</tr>

Disable Date Time Picker Control on NewForm.aspx, Edit Form.aspx using JQuery in SharePoint

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>    
<script type="text/javascript">  
$(function() {   
$( "td.ms-dtinput > input[id$='DateTimeFieldDate']" ).attr('readonly''readonly');
$( "td.ms-dtinput > a" ).attr('onclick','').unbind('click');   
});
</script> 

Clearing Person/Group Values

To clear out or empty the values in person or group columns, how you do it depends on if the column is single-value or multi-value. For ...