Thursday, 24 December 2015
Setting up MongoDB
Installation Procedure:
- If your system is running on one of these Windows Server 2008 R2, Windows Vista, or windows 7 Please follow the below
- To resolve memory mapping issues while installing MongoDB one has to install a hotfix from https://support.microsoft.com/en-gb/kb/2731284 which has a link to download hotfix sent through an email .
- There are 3 builds of MongoDB for Windows
- MongoDB for Windows 64 bit
- MongoDB for Windows 32 bit
- MongoDB for Windows 64 bit legacy
Download the
latest release compatible with your system from the link: http://www.mongodb.org/downloads?_ga=1.149793334.1228321965.1432748496


- Once the download is complete,double click on the installer package and follow the installation wizard. While installing you must specify a installation directory by choosing “Custom” option, The installation wizard will assume that you have installed at C:\mongodBy following the above procedure the following 10+ executable files will installed in the bin folder. And they are required files to MongoDB mongod.exe, mongo.exe, mongodump.exe, mongorestore.exe, mongoimport.exe, mongoexport.exe, mongostat.exe, and mongotop.exe.
- MongoDB need a folder (data directory) to store its data. By default, it will store in “C:\data\db“, create this folder manually. MongoDB won’t create it for you.
- It’s recommended to add C:/MongoDB/Server/3.0/bin to Windows environment variable, so that you can access the MongoDB’s commands in command prompt easily as shown

Setting up Eclipse for MongoDB:
- To connect to mongodb from java, we need to install mongodb java driver.
- Get jar file of mongodb Java driver from: http://docs.mongodb.org/ecosystem/drivers/java/
- Let’s see with an example how to work with mongodb java.
- In eclipse: create dynamic web project. Right click project->configure build path->Add external Jars. Select and add mongo db java jar to build path.

- Add jar file to class path also: Run->Run configuration-> select your server-> class path. Add jar files.
This
completes setting up mongo db. Now you can start writing code to connect to
mongo db and perform operation on mongodb.
Saturday, 12 December 2015
Inserting and retrieving values for all types of Fields in ShrePoint 2013 using JSOM
//Inserting into all types of fields
function insertItem()
{
var context=new SP.ClientContext.get_current();
var web=context.get_web();
context.load(web);
var list=web.get_lists().getByTitle("FieldsTypeDemo1");
context.load(list);
var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = list.addItem(itemCreateInfo);
oListItem.set_item("SingleText",SingleText);
oListItem.set_item("MultiPlainText",MultiPlainText);
oListItem.set_item('MultiRichText',MultiRichText);
oListItem.set_item('ChoiceDropDown',ChoiceDropDown);
oListItem.set_item('ChoiceRadio',ChoiceRadio);
oListItem.set_item('ChoiceCheckBox',ChoiceCheckBox);
oListItem.set_item('Num',Num);
oListItem.set_item('Currency',Currency);
//Convert date to SharePoint Date format
if(DateOnly!="")
{
var toDate=new Date(DateOnly);
var newDateOnly=(toDate.getMonth()+1)+"/"+toDate.getDate()+"/"+toDate.getFullYear();
oListItem.set_item('DateOnly',newDateOnly);
}
//Convert date and time to SharePoint DateTime format
if(DateAndTime!="")
{
//alert(time[0]);
var toDate1=new Date(DateAndTime);
var newDateTime=(toDate1.getMonth()+1)+"/"+toDate1.getDate()+"/"+toDate1.getFullYear()+" "+hr+min;
alert(newDateTime);
oListItem.set_item('DateAndTime',newDateTime);
}
var lookUp = new SP.FieldLookupValue();
lookUp.set_lookupId(LookUpField);
oListItem.set_item('LookUpField',lookUp);
oListItem.set_item('Y_x002f_N',YN);
if(HyperLink!="http://")
oListItem.set_item('HyperLink',HyperLink);
if(Picture!="http://")
oListItem.set_item('Picture',Picture);
//Converting to Taxonomy Managed metadata field
if(ManagedMetadata!="")
{
var field= list.get_fields().getByInternalNameOrTitle("ManagedMetadata");
var taxField = context.castTo(field, SP.Taxonomy.TaxonomyField);
var termValue = new SP.Taxonomy.TaxonomyFieldValue();
var id="";
for(var i=0;i<termsLbl.length;i++)
{
if(termsLbl[i]==ManagedMetadata)
{
id=termsId[i];
}
}
termValue.set_label(ManagedMetadata);
termValue.set_termGuid(id);
taxField.setFieldValueByValue(oListItem, termValue);
}
oListItem.update();
context.load(oListItem);
context.executeQueryAsync(success,fail);
function success()
{
alert("Row Inserted Successfully");
window.location.reload();
}
function fail(sender,args)
{
alert(args);
window.location.reload();
}
function insertItem()
{
var context=new SP.ClientContext.get_current();
var web=context.get_web();
context.load(web);
var list=web.get_lists().getByTitle("FieldsTypeDemo1");
context.load(list);
var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = list.addItem(itemCreateInfo);
oListItem.set_item("SingleText",SingleText);
oListItem.set_item("MultiPlainText",MultiPlainText);
oListItem.set_item('MultiRichText',MultiRichText);
oListItem.set_item('ChoiceDropDown',ChoiceDropDown);
oListItem.set_item('ChoiceRadio',ChoiceRadio);
oListItem.set_item('ChoiceCheckBox',ChoiceCheckBox);
oListItem.set_item('Num',Num);
oListItem.set_item('Currency',Currency);
//Convert date to SharePoint Date format
if(DateOnly!="")
{
var toDate=new Date(DateOnly);
var newDateOnly=(toDate.getMonth()+1)+"/"+toDate.getDate()+"/"+toDate.getFullYear();
oListItem.set_item('DateOnly',newDateOnly);
}
//Convert date and time to SharePoint DateTime format
if(DateAndTime!="")
{
//alert(time[0]);
var toDate1=new Date(DateAndTime);
var newDateTime=(toDate1.getMonth()+1)+"/"+toDate1.getDate()+"/"+toDate1.getFullYear()+" "+hr+min;
alert(newDateTime);
oListItem.set_item('DateAndTime',newDateTime);
}
var lookUp = new SP.FieldLookupValue();
lookUp.set_lookupId(LookUpField);
oListItem.set_item('LookUpField',lookUp);
oListItem.set_item('Y_x002f_N',YN);
if(HyperLink!="http://")
oListItem.set_item('HyperLink',HyperLink);
if(Picture!="http://")
oListItem.set_item('Picture',Picture);
//Converting to Taxonomy Managed metadata field
if(ManagedMetadata!="")
{
var field= list.get_fields().getByInternalNameOrTitle("ManagedMetadata");
var taxField = context.castTo(field, SP.Taxonomy.TaxonomyField);
var termValue = new SP.Taxonomy.TaxonomyFieldValue();
var id="";
for(var i=0;i<termsLbl.length;i++)
{
if(termsLbl[i]==ManagedMetadata)
{
id=termsId[i];
}
}
termValue.set_label(ManagedMetadata);
termValue.set_termGuid(id);
taxField.setFieldValueByValue(oListItem, termValue);
}
oListItem.update();
context.load(oListItem);
context.executeQueryAsync(success,fail);
function success()
{
alert("Row Inserted Successfully");
window.location.reload();
}
function fail(sender,args)
{
alert(args);
window.location.reload();
}
}
//retriving from all types of fields
function getAllItems()
{
var context=new SP.ClientContext.get_current();
var web=context.get_web();
context.load(web);
var list=web.get_lists().getByTitle("FieldsTypeDemo1");
context.load(list);
var query = new SP.CamlQuery();
var items = list.getItems(query);
context.load(items);
context.executeQueryAsync(success,fail);
function fail(sender,args)
{
alert("Call failed:"+args.get_message());
}
function success()
{
var item = items.getEnumerator();
while(item.moveNext())
{
var row = item.get_current();
$("#SingleTextInfo").text(row.get_item("SingleText"));
$("#MultiPlainTextInfo").text(row.get_item("MultiPlainText"));
document.getElementById("MultiRichTextInfo").innerHTML=row.get_item("MultiRichText");
$("#ChoiceDropDownInfo").text(row.get_item("ChoiceDropDown"));
$("#ChoiceRadioInfo").text(row.get_item("ChoiceRadio"));
$("#ChoiceCheckBoxInfo").text(row.get_item("ChoiceCheckBox"));
$("#NumInfo").text(row.get_item("Num"));
$("#CurrencyInfo").text(row.get_item("Currency"));
var date1=new Date(row.get_item("DateOnly"));
$("#DateOnlyInfo").text(((date1.getMonth()+1)+"/"+date1.getDate()+"/"+date1.getFullYear()));
var date2=new Date(row.get_item("DateAndTime"));
$("#DateAndTimeInfo").text(((date2.getMonth()+1)+"/"+date2.getDate()+"/"+date2.getFullYear()+" "+date2.getHours()+":"+date2.getMinutes()));
//get Lookup value for look up field
$("#LookUpFieldInfo").text(row.get_item("LookUpField").get_lookupValue());
if(row.get_item("Y_x002f_N")==true)
$("#YNInfo").text("Yes");
else
$("#YNInfo").text("No");
//get URL for HyperLink an dPicture fields
var url1=row.get_item("HyperLink").get_url();
var url2=row.get_item("Picture").get_url();
document.getElementById("HyperLinkInfo").innerHTML='<a href="'+url1+'" target="new">'+url1+'</a>';
document.getElementById("PictureInfo").innerHTML='<a href="'+url2+'" target="new">'+url2+'</a>';
//display label name
$("#ManagedMetadataInfo").text(row.get_item("ManagedMetadata").$0_1);
}
}
}
Tuesday, 8 December 2015
JSOM To Create WorkFlow in Sharepoint 2013
If you want to pro-grammatically create workflow in SharePoint 2013 use following steps:
1. First create workflow in SharePoint Designer 2013.
This will save workflow.wsp in SiteAsstes. Download that.
3. Change the extension of workflow.wsp to .cab. This converts file to RAR file. Extract it.
4. Get the file from "Files\wfsvc\87f127f963084cdf884a683bcb76e3e0 ". content of this file is used as xaml in below code.
var ctx = SP.ClientContext.get_current();
var servicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web());
var definition = SP.WorkflowServices.WorkflowDefinition.newObject(ctx, ctx.get_web());
definition.set_xaml(xaml);
definition.set_displayName("Test");
var deploymentService = servicesManager.getWorkflowDeploymentService();
deploymentService.saveDefinition(definition);
ctx.load(definition);
ctx.executeQueryAsync(function () {
deploymentService.publishDefinition(definition.get_id());
ctx.executeQueryAsync(function () {
var subscription = SP.WorkflowServices.WorkflowSubscription.newObject(ctx, ctx.get_web());
subscription.set_name("Test");
subscription.set_enabled(true);
subscription.set_definitionId(definition.get_id());
var targetListId="07E21547-3ACD-4297-909E-6660F443E892";
subscription.set_eventSourceId(targetListId);
subscription.set_eventTypes(["ItemAdded"]);
var subscriptionService = servicesManager.getWorkflowSubscriptionService();
subscriptionService.publishSubscriptionForList(subscription, targetListId);
ctx.executeQueryAsync(function () {
console.log("done");
},function (sender,arg) {
console.log(arg.get_message());
});
});
});
Monday, 7 December 2015
Code Snippet:Auto Complte text box for SharePoint users
function getSiteUsers()
{
var call=jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/siteusers",
type:"GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
});
call.done(function(data,textStatus,jqXHR){
var users=data.d.results;
var usrs=[];
for(var i=0;i<users.length;i++)
{
if(users[i].UserId!=null&&users[i].LoginName.indexOf("onmicrosoft.com")!=-1)
{
usrs.push(users[i].Title);
}
}
$( "#email" ).autocomplete
({
/*Source refers to the list of fruits that are available in the auto complete list. */
source:usrs,
/* auto focus true means, the first item in the auto complete list is selected by default. therefore when the user hits enter,
it will be loaded in the textbox */
autoFocus: true ,
});
});
call.fail(function(jqXHR,textStatus,errorThrown){
var response=JSON.parse(jqXHR.responseText);
var msg=response ? response.error.message.value : "Error";
alert("Call Failed:"+msg);
});
}
<input type="text" id="email" name="email"/>
- _spPageContextInfo.webAbsoluteUrl+"/_api/web/siteusers" url gives you all site users along. Say for example My sharepoint site has only one user i.e "Madhumati Hosamani" along with this users there are some existing site users will be returned.
- [15:02:20.490] Everyone
[15:02:20.490] Everyone except external users
[15:02:20.490] madhumati hosamani
[15:02:20.490] NT AUTHORITY\authenticated users
[15:02:20.490] _SPOCacheFull
[15:02:20.490] _SPOCacheRead
[15:02:20.490] System Account
[15:02:20.490] YLO001\_spocrwl_337_16600
- To filter and get only site use, I have used following logic
This checks that UserID should not be null which is null in case of ['Everyone', 'Everyone except external users' and 'NT AUTHORITY\authenticated users'] and site user login name ends with onmicrosoft.com.
- To set it to autocomplete of text box use following snippet:
- $( "#email" ).autocomplete
({
/*Source refers to the list of fruits that are available in the auto complete list. */
source:usrs,
/* auto focus true means, the first item in the auto complete list is selected by default. therefore when the user hits enter,
it will be loaded in the textbox */
autoFocus: true ,
});
Subscribe to:
Posts (Atom)










