public String writeAlertCount(String accessToken, String InputCol1, String InputCol2, Container container) throws StreamTransformationException{
/**
* Using this function, we can update AlertCountList items of SharePoint.
* Suppose, if we want to insert data into two columnItems ('Col1' & 'Col2') of AlertCountList in SharePoint, then following SharePoint-REST will be consumed inside this UDF
* REST URL: https://<org_Shp_Host>/teams/SPdev/AlertsCount/_api/web/Lists/GetByTitle('AlertCount')/Items
* Request Format:
* {__metadata: { 'type': 'SP.Data.AlertCountListItem' }, Col1: 'E01', Col1: '1562' } *
* Where,
* <org_Shp_Host> is Organisation's SharePoint host name
*/
String response = "";
try {
//SharePoint REST url to update AlertCount Item List
String wsURL = "https://<org_Shp_Host>/teams/SPdev/AlertsCount/_api/web/Lists/GetByTitle('AlertCount')/Items";
// Create Http Connection
URL url = new URL(wsURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
// Set Header
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Authorization", "Bearer " + accessToken);
httpConn.setRequestProperty("accept","application/json;odata=verbose");
httpConn.setRequestProperty("content-Type", "application/json;odata=verbose");
// Set Request parameters
String requestP = "{__metadata: { 'type': 'SP.Data.AlertCountListItem' }, "
+ "Col1: '" + InputCol1 +"', "
+ "Col2: '" + InputCol2+"' }";
// Send Request
DataOutputStream wr = new DataOutputStream(httpConn.getOutputStream());
wr.writeBytes(requestP);
wr.flush();
wr.close();
//Read the response
if (httpConn.getResponseCode() == 200) {
response = "Http Response Code: " + httpConn.getResponseCode();
}else if (httpConn.getResponseCode() == 201) {
// when HttpResponseCode is 201, this insert is successful in SharePoint.
response = "Http Response Code: " + httpConn.getResponseCode() + "\n Item inserted successfully in sharepoint";
}else{
response = "Error with Http Response Code: " + httpConn.getResponseCode();
}
} catch (Exception e) {
response = "Error: " + e.getMessage();
}
return response;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
12 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |