Monday, February 5, 2018

SP.ClientContext (siteURL) error this.set_formDigestHandlingEnabled

When you are using Site URL to get ClientContext use 'new' keyword while define else you will see error...
this.set_formDigestHandlingEnabled


example.
$(document).ready(function () {

    //get context 
    context = new SP.ClientContext(siteURL);
    web = context.get_web();

});

Thursday, February 1, 2018

How to Set any SPField Value with JSOM

How to set any SP.Field Value with JSOM (Javascript) in Sharepoint 2013 to New SP.Listitem



 function createListItem() {  
   var clientContext = new SP.ClientContext(_spPageContextInfo.siteAbsoluteUrl);  
   var oList = clientContext.get_web().get_lists().getByTitle('TestList');  
   var itemCreateInfo = new SP.ListItemCreationInformation();  
   this.oListItem = oList.addItem(itemCreateInfo);
  
   //Single line of text  
   oListItem.set_item('Title', 'My New Item!'); 
 
   //Single Choice  
   oListItem.set_item('PetkaChoiceDrop', 'Enter Choice #1');  

   //Multi Choice  
   var petkaChoiceMultiArray = new Array("Enter Choice #1","Enter Choice #2");    
   oListItem.set_item('PetkaChoiceMulti', petkaChoiceMultiArray);  

   //Single Lookup  
   var PetkaLookupSingle = new SP.FieldLookupValue();  
   PetkaLookupSingle.set_lookupId(2);  
   oListItem.set_item('PetkaLookup', PetkaLookupSingle);  

   //Multi Lookup  
   var lookupsIds = [1,2];  
   var lookups = [];  
   for (var ii in lookupsIds) {  
      var lookupValue = new SP.FieldLookupValue();  
      lookupValue.set_lookupId(lookupsIds[ii]);  
      lookups.push(lookupValue);  
   }  
   oListItem.set_item('PetkaLookupMulti', lookups);
  
   //Yes=1 / No=0  
   oListItem.set_item('PetkaYesNo', 1);  

   // Single Person  
   var singleUser = SP.FieldUserValue.fromUser('Peter Dotsenko');  
   oListItem.set_item('PetkaPersonSingle', singleUser);  
   
   //Multi Person  
   var petkaUserMultiArray = new Array("peterd@domain.com","Peter Dotsenko","domain\\peterd");  
   var lookups = [];  
   for (var ii in petkaUserMultiArray) {  
      var lookupValue = SP.FieldUserValue.fromUser(petkaUserMultiArray[ii]);  
      lookups.push(lookupValue);  
   }  
   oListItem.set_item('PetkaPersonMulti', lookups); 
 
   //Managed Multi  
   var field = oList.get_fields().getByInternalNameOrTitle("PetkaManagedMulti");  
   var taxField = clientContext.castTo(field, SP.Taxonomy.TaxonomyField);  
   var terms = new SP.Taxonomy.TaxonomyFieldValueCollection(clientContext,getMultiTax(),taxField);  
   taxField.setFieldValueByValueCollection(oListItem, terms);  

   //Managed Single  
   var field = oList.get_fields().getByInternalNameOrTitle("PetkaManagedSingle");  
   var taxField = clientContext.castTo(field, SP.Taxonomy.TaxonomyField);  
   var taxonomySingle = new SP.Taxonomy.TaxonomyFieldValue();  
   taxonomySingle.set_label("Mamo");  
   taxonomySingle.set_termGuid("10d05b55-6ae5-413b-9fe6-ff11b9b5767c");  
   taxonomySingle.set_wssId(-1);  
   taxField.setFieldValueByValue(oListItem, taxonomySingle);
  
   //Hyperlink or Picture  
   var hyperLink = new SP.FieldUrlValue();  
   hyperLink.set_url("http://cnn.com");  
   hyperLink.set_description("CNN");  
   oListItem.set_item('PetkaHyperLink', hyperLink);
  
   //Currency  
   oListItem.set_item('PetkaCurrency', '100');
  
   //DateTime  
   oListItem.set_item('PetkaDateTime', '3/14/2014'); 
 
   //MultiLine text  
   oListItem.set_item('PetkaMultiText', 'Hello!

');
  
   oListItem.update();  
   clientContext.load(oListItem);  
   clientContext.executeQueryAsync(  
     Function.createDelegate(this, this.onQuerySucceeded),   
     Function.createDelegate(this, this.onQueryFailed)  
   );  
 }

function getMultiTax(){  
      var terms = new Array();  
      terms.push("-1;#Mamo|10d05b55-6ae5-413b-9fe6-ff11b9b5767c");  
      terms.push("-1;#Popo|178888b0-7942-45bb-b3f1-2f38d476e3db");  
      return terms.join(";#");  
}

function onQuerySucceeded() {
    SP.UI.Notify.addNotification('Item created: ' + oListItem.get_id());
}

function onQueryFailed(sender, args) {
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  

Monday, January 1, 2018

SharePoint User Information List – URL

Following is the details of URL to get “User Information List”.

By using follwoing code, we can get the Users list url,

SPList userList = SPContext.Current.Web.SiteUserInfoList;
string url = userList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url;

the above code will return like the following url http://mysite/_layouts/userdisp.aspx. But, this url is not the exact url.

The actual url for “User Information List” available under _Catalogs folder, shown as below

http://mysite/_catalogs/users/detail.aspx
            Shows the detail view of only Users in the list.
http://mysite/_catalogs/users/simple.aspx
            Shows the simple view of only Users in the List
http://mysite/_catalogs/users/allgroups.aspx
            Shows all the groups without users available in Site.



Reference : site link

Saturday, November 18, 2017

Conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

Solution:
"The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value" with Entity Framework when calling SaveChanges.

Go into your EDMX file, select the field that is causing the error and set StoreGeneratedPattern to Computed.








Add the DatabaseGenerated attribute if you are using EF Code First:

[DatabaseGenerated(DatabaseGeneratedOption.Computed)]

public Nullable<System.DateTime> Created { get; set; }

Tuesday, November 14, 2017

Clearing Your Browser Cache

Notes:
If you don't see instructions below for your specific version or browser, search your browser's Help menu for "clear cache". If you're unsure what browser version you're using, from the Help menu, select About [browser name]. In Internet Explorer and Firefox, if you don't see the menu bar, press and release Alt.
When troubleshooting issues with any web site, after clearing your browser's cache and cookies, exit your browser completely before attempting to access the site again. In Windows, close all your browser windows; in Mac OS X, quit (Command-q) your browser.

On this page:

About cache, cookies, and history
Android
Chrome
Firefox
Internet Explorer 9 and 8
Mobile Safari for iPhone OS (iPhone, iPod touch, iPad)
Safari

About cache, cookies, and history

Each time you access a file through your web browser, the browser caches (i.e., stores) it. By doing this, the browser doesn't have to retrieve files and images from the web site each time you click Back or Forward.

A cookie is a file created by a web browser, at the request of a web site, that is then stored on your computer. These files typically store user-specific information such as selections in a form, shopping cart contents, or authentication data.

A browser's history is a log of sites that you visit. When you press a browser's Back button, you are moving back one entry in the history log.

Android

Start your browser.
Tap Menu, and then tap More.
Select Settings.
Under "Privacy settings", select Clear cache, Clear history, or Clear all cookie data as appropriate, and then tap OK to accept (or Cancel to cancel) the deletion.

Chrome

In the browser bar, enter: chrome://settings/clearBrowserData
Select the items you want to clear (e.g., Clear browsing history, Clear download history, Empty the cache, Delete cookies and other site and plug-in data).
From the Obliterate the following items from: drop-down menu, you can choose the period of time for which you want to clear cached information. To clear your entire cache, select the beginning of time.
Click Clear browsing data.

Firefox

From the Tools or History menu, select Clear Recent History.
If the menu bar is hidden, press Alt to make it visible.
From the Time range to clear: drop-down menu, select the desired range; to clear your entire cache, select Everything.
Click the down arrow next to "Details" to choose which elements of the history to clear.
Click Clear Now.

Internet Explorer 9 and 8

Click Tools, and select Delete Browsing History... .
Deselect Preserve Favorites website data, and select Temporary Internet files, Cookies, and History.
Click Delete.

Mobile Safari for iPhone OS (iPhone, iPod touch, iPad)

To clear cache and cookies:
From the home screen, tap Settings, and then tap Safari.
At the bottom of Safari's settings screen, tap Clear cookies and data, or Clear Cookies and Clear Cache. Confirm when prompted.

To clear history:
From the home screen, tap Safari.
At the bottom of the screen, tap the Bookmarks icon.
In the lower left, tap Clear.
Tap Clear History.

Safari

From the Safari menu, select Reset Safari... .
From the menu, select the items you want to reset, and then click Reset. As of Safari 5.1, Remove all website data covers both cookies and cache.


Reference Site: https://mso.harvard.edu/sp_clear_cache

Tuesday, September 5, 2017

Quickly create a dynamic drop down list in Excel

I have a request from friend to create a dynamic drop down list in excel and I would like to share with my blog reader...

Part  1: 
- Open Excel and we start by creating a defined name, 
- Select the Formulas Tab, then Define
- Enter "SomeRangeName" under the Name text box
- Enter =OFFSET(sheet1!$B$2,0,0,COUNTA(sheet1!$B:$B),1) under the Refers to text box

Note: You have to enter drop down items in single column you want here in above formula I have selected Sheet1 and column B, it will start filtering from Row B2.

Part 2:
To create a data validation list:

- Select the cell you want to show dropdown list eg. A1
- Select Data Validation under the Data Tab
- Select List under Allow
- Place the cursor in the Source text box and type formula "=SomeRangeName"

That's it.. now when ever you add items in "Column B" it will automatically populate in drop down list... 

Tuesday, August 22, 2017

Getting Geo-location with JSon and JQuery


$.getJSON("https://freegeoip.net/json/", function(data) {
    const countryCode = data.country_code;
    const countryName = data.country_name;
    const ip = data.ip;
    const timezone = data.time_zone;
    const latitude = data.latitude;
    const longitude = data.longitude;

    alert("Country Code: " + countryCode);
    alert("Country Name: " + countryName);
    alert("IP: " + ip); 
    alert("Time Zone: " + timezone);
    alert("Latitude: " + latitude);
    alert("Longitude: " + longitude);   
});
Credit goes to original coder..