Thursday, November 26, 2015

How to display workflow related tasks in the item display page where the workflow is currently running on in SharePoint2013

https://ybbest.wordpress.com/2013/05/30/how-to-display-workflow-related-tasks-in-the-item-display-page-where-the-workflow-is-currently-running-on-in-sharepoint2013/

Wednesday, November 25, 2015

How to load Javascript file properly

  1. The path may not be resolved correctly (sometimes relative urls seem just not to work correctly in SharePoint context)
  2. When using jQuery in Javascript within e.g. a SharePoint webpart try to use jQuery.noConflict() before using the SP-Services. In most cases I had issues with using $ or jQuery because of the already loaded JQuery within SharePoint.
  3. When using javascript in SharePoint $(document).ready might cause problems because this doesn´t actually mean that all content is loaded. You can try to use _spBodyOnLoadFunctionNames.push("myfunction") instead.
  4. Use ExecuteOrDelayUntilScriptLoaded(temp(), "jquery-1.10.1.min.js");
  5. $.getScript("jquery.SPServices-0.7.2.min.js",[optionalFunction() { }]); OptionalFunction() will execute after jquery in 1st parameter loaded successfully

Friday, November 20, 2015

How to update/insert item in SharePoint list or list form using SPService



function UpdateItem(fieldInternalName,fieldValue)
{
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "Update",
listName: "Sub Investment",
valuepairs: [[fieldInternalName, fieldValue]],
completefunc: function(xData, Status)
{ alert("Yahoo! Item updated"); }
});
}

batchCmd: "Update" or "New".
listName: display name of list.

How to get item from list using SPServices

<script src="../../Style Library/jquery.SPServices-0.7.2.min.js" type="text/javascript"> </script>
<script>
var v = GetLatestSubInvestmentID();

function GetLatestSubInvestmentID()
{

var myQuery = "<Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where><OrderBy><FieldRef Name='Created' Ascending='FALSE' /></OrderBy></Query>";
$().SPServices({
   webUrl: "http://skl241:25625/sites/InvestmentDB/",
   operation: "GetListItems",
   async: false,
   listName: "Sub Investment IDs",
   CAMLQuery: myQuery,
   CAMLRowLimit:1,
   CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='InvestmentInfo' /></ViewFields>",
   completefunc: function (xData, Status)
   {
   
       $(xData.responseXML).SPFilterNode("z:row").each(function()
       {
        vGetLatestSubInvestmentID= $(this).attr("ows_InvestmentInfo");
        $("input[Title='Total Amount Alloted']").val(vGetLatestSubInvestmentID);

      });//End of each()
   }//End of completefunc
 
 });//End of SPServices
return vGetLatestSubInvestmentID;
}//End of GenerateSubInvestmentID
</script>

Pad a number with leading zeros in JavaScript or Jquery

var v = pad(10,4); output as 0010


function pad(n, width, z)
{
 z = z || '0';
 n = n + '';
 return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}