Posts

Showing posts with the label ecmascript

SharePoint 2010 - Simple Cascading Lookup with SPServices

Image
A new post on that excellent tool that is SPServices, the jQuery framework / EcmaScript for SharePoint! A simple scenario: we have two lists of data, for example, Countries and Companies for Countries, and a list which has two columns Lookup, Country and Company. We want to be able to use the first Lookup, Country, to filter second, Company, showing Companies for the selected Country. We create the list Nations, with only the Title field. Now let's create Companies with Title (Company Name) and Country (lookup list to the Nations). Now, let's create a list CustomList1 that has the two columns Country and Company, respectively lookup of Nations and Companies. We modify the NewForm.aspx and EditForm.aspx form by entering the following code, making sure to load the SiteAssets. Js file we need: jquery.SPServices-0.7.2.min.js ( download here ) jquery-1.8.2.min.js (tested with this version) Here's the code to insert in both forms (new and edit): <sc...

SharePoint 2010 - Semplice Cascading Lookup con SPServices

Image
Ancora un post su quell'ottimo strumento che รจ SPServices, il framework jQuery/Ecmascript per SharePoint! Uno scenario semplice: abbiamo due liste di anagrafiche, ad esempio, Nazioni e Aziende per Nazioni, e una lista che ha le due colonne Lookup, Nazione e Azienda. Vogliamo poter utilizzare la prima Lookup, Nazione, per filtrare la seconda, Azienda, per le sole Aziende per il Paese selezionato. Creiamo la lista Nazioni, con il solo campo Title. Ora creiamo la lista Aziende con Title (Nome Azienda) e Nazione (lookup verso la lista Nazioni). Ora, creiamo una lista CustomList1 che abbia le due colonne Nazione e Azienda, rispettivamente lookup di Nazioni e Aziende. Modifichiamo i form NewForm.aspx e EditForm.aspx, inserendo il codice che segue, avendo cura di caricare in SiteAssets i file .js di cui abbiamo bisogno: jquery.SPServices-0.7.2.min.js ( download qui ) jquery-1.8.2.min.js (testato con questa versione) Ecco il codice da inserire in entrambi i form (n...

Sharepoint 2010 - Enable/Disable Ribbon Button with EcmaScript

I show you a detailed example of how to enable and disable a ribbon button according to the current user’s group. The example uses “EnabledScript” attribute of the CommandUIHandler of the ribbon button. Then the EnabledScript is built with EcmaScript to find groups and user info. Lets Start with creating a Ribbon button first. 1. Create a empty project. 2. Deploy it as a Farm solution. 3. Right click on the feature and click “Add feature”. 4. Right click on the project and add a new “Empty Element” item. 5. Next add the below code to add a custom Ribbon button to your document library. <Elements xmlns=”http://schemas.microsoft.com/sharepoint/” > <CustomAction Id=”ButtonForGroupUsersOnly” Location=”CommandUI.Ribbon” RegistrationId=”101″ RegistrationType=”List” Title=”Owners Group Button”> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location=”Ribbon.Library.ViewFormat.Controls._children”> <Button Id=”Ribbon.L...

Sharepoint 2010 - Modify Documents Properties with ECMA Script

Finally I found the way to modify document properties with ECMA Script! It's not an hard work for Document Libraries with no mandatory check out. Here the script: function updateDocument(action, docLibId, docId, fieldName, fieldValue) {     var context = new SP.ClientContext.get_current();       var web = context.get_web();       var docLibGuid = new SP.Guid(docLibId);       var docLib = web.get_lists().getById(docLibGuid);       var doc = docLib.getItemById(docId);       doc.set_item(fieldName, fieldValue);         doc.update();       context.executeQueryAsync(Function.createDelegate(this, this.successUpdateDocument), Function.createDelegate(this, this.failed));  } function successUpdateDocument(sender, args) {       //reload page if success       location.reload(true); } But when we set check out mandatory, we ...