Friday, June 15, 2018

Workplace API authentication - Azure function app






#r "Newtonsoft.Json"
using System.Net;
using System.Net.Http;
using Newtonsoft.Json;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var myObj = new {hub_challenge="hub.challenge" };
var errObj = new {response="noresponse" };

// parse query parameter
string HUB_MODE = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "hub.mode",true) == 0)
.Value;

string VERIFY_TOKEN = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "hub.verify_token", true) == 0)
.Value;

string ACCESS_TOKEN = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "ACCESS_TOKEN", true) == 0)
.Value;

// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();

var jsontoreturn = (HUB_MODE == "subscribe" && VERIFY_TOKEN == "12345")
? JsonConvert.SerializeObject(myObj)
: JsonConvert.SerializeObject(errObj);

return req.CreateResponse(HttpStatusCode.OK, jsontoreturn, "application/json");


}

Wednesday, March 28, 2018

Autocomplete feature in SharePoint Online



code for Autocomplete feature in sharePoint edit column..




<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://jqueryui.com//resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
var availableTags=function() {
var results=null;
var siteurl = _spPageContextInfo.webAbsoluteUrl;
$.ajax({
async: false,
url: siteurl + "/_api/web/lists/getbytitle('listname')/items?$select=Title",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
if (data.d.results.length > 0 ) {
results=data.d.results.map(function(i){return i.Title})
}
},
error: function (data) {
alert("Error: "+ data);
}
});
return results
}();

alert(availableTags)
$("input[id^='showautocompletefield']").autocomplete({
source: availableTags
});
} );
</script>
</head>
<body>
</body>
</html>

Wednesday, January 9, 2013

Sort date in Xml using XSLT

Here is how we can sort in given XML using XSLT



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
  <xsl:output method="text"/>
  <xsl:template match="Records">
    <xsl:apply-templates>
         <!-- year part -->
         <xsl:sort select="substring-after(substring-after(@OrderDate,'/'),'/')"    />
         <!-- month part -->
         <xsl:sort select="substring-before(substring-after(@OrderDate,'/'),'/')"  />
         <!-- day part -->
         <xsl:sort select="substring-before(@OrderDate,'/')"       />
          </xsl:apply-templates>
  </xsl:template>
  <xsl:template match="Order">
     <xsl:if test="position() = 1">
   <xsl:value-of select="@OrderDate"/> <br/>
   </xsl:if>
    </xsl:template>
</xsl:stylesheet>


To test the functionality use the following Sample XML. Use the below Url to test http://www.w3schools.com/Xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog

<root>
    <Records>
         <Order OrderDate="14/01/2011"> </Order>  
          <Order OrderDate="05/01/2011"> </Order> 
          <Order OrderDate="08/01/2011"> </Order>  
          <Order OrderDate="10/01/2011"> </Order>  
   </Records>
</root>