Sharepoint 2010: create new list items using pure javascript
Ozzie
On Sharepoint 2010, every site has a Representational State Transfer (REST) interface. The SharePoint 2010 Representational State Transfer (REST) interface is a WCF Data Service that allows you to use construct HTTP requests to query SharePoint list data. The URL of this WCF service will be in the form:
The data and operations are represented and supported using the OData protocol. The Open Data Protocol (OData) enables the creation of HTTP-based data services, which allow resources identified using Uniform Resource Identifiers (URIs) and defined in an abstract data model, to be published and edited by Web clients using simple HTTP messages.
As described above in the OData documentation, a Service Document is exposed that lists all the top-level feeds so clients can discover them and find out the addresses of each of them. The service document is typically available at the Service Root URI and may be formatted in Atom or JSON as described in [OData: Atom] and [OData: JSON].
Mapping this concept to the Sharepoint 2010 architecture, the service document URI is our ListData.svc address and the top level feed will be an Atom feed with all the Sharepoint Lists existing at the site. The feed for a specific list will have the address:
Having explained this, one can go through the steps of creating a simple javascript to use AJAX and JSON to create a new list item. For this we will use:
Next, create the fucntion that will add the new item to the target list:
To fit this all together, use an HTML form to input the required fields and a button that calls the add new item function "addNewItem()".
Happy programming!
http://[your sharepoint site URL]/_vti_bin/ListData.svc
As described above in the OData documentation, a Service Document is exposed that lists all the top-level feeds so clients can discover them and find out the addresses of each of them. The service document is typically available at the Service Root URI and may be formatted in Atom or JSON as described in [OData: Atom] and [OData: JSON].
Mapping this concept to the Sharepoint 2010 architecture, the service document URI is our ListData.svc address and the top level feed will be an Atom feed with all the Sharepoint Lists existing at the site. The feed for a specific list will have the address:
http://[your sharepoint site URL]/_vti_bin/ListData.svc/[your list name]
Having explained this, one can go through the steps of creating a simple javascript to use AJAX and JSON to create a new list item. For this we will use:
- datajs: a new cross-browser JavaScript library that enables data-centric web applications by leveraging modern protocols such as JSON and OData and HTML5-enabled browser features. It's designed to be small, fast and easy to use.
- json: became a built-in feature of JavaScript when the ECMAScript Programming
Language Standard - Fifth Edition was adopted by the ECMA General Assembly
in December 2009. However, if you have run-time problems, you can try to include this. - jQuery: fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.
< script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js" type="text/javascript"> < /script> < script src="datajs-1.0.2.min.js" type="text/javascript"> < /script> < script src="json2.js" type="text/javascript"> < /script>
Next, create the fucntion that will add the new item to the target list:
function addNewItem() {
// create a typeless JS object and fill it with values for the new list item
var newItem = { attribute1: $("#formField1").val(),
attribute2: $("#formField2").val(),
attribute3: $("#formField3").val()};
// create the JS object to pass as parameter to the OData request
var requestOptions = { requestUri: "[your list URL]", method: "POST", data: newItem };
// call OData.request to add item with HTTP POST operation
OData.request(requestOptions, OnSuccess, OnError);
}
Finally, create callback function the handle success and error outcomes:function OnSuccess(data, request) {
alert("Success!");
}
function OnError(error) {
alert(JSON.stringify(error));
}
To fit this all together, use an HTML form to input the required fields and a button that calls the add new item function "addNewItem()".
Happy programming!
1:38 PM
javascript
,
Programming
,
sharepoint
MS-SQL–Get all tables with a given column name
Ozzie
Using Microsoft SQL Server, found this to be handy sometimes:
USE [your database name]
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%given column name%'
ORDER BY schema_name, table_name;
HTH.
USE [your database name]
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%given column name%'
ORDER BY schema_name, table_name;
HTH.
11:36 AM
Programming
,
sql server
,
Systems Administration
Free ebook: Introducing Microsoft SQL Server 2012
Ozzie
Here is a very nice freebie from Microsoft Press. The final and complete version of Introducing Microsoft SQL Server 2012, by Ross Mistry (@RossMistry) and Stacia Misner (@StaciaMisner), is available as a free download. Introducing Microsoft SQL Server 2012 includes 10 chapters:
PART I DATABASE ADMINISTRATION (by Ross Mistry)
1. SQL Server 2012 Editions and Engine Enhancements
2. High-Availability and Disaster-Recovery Enhancements
3. Performance and Scalability
4. Security Enhancements
5. Programmability and Beyond-Relational Enhancements
PART II BUSINESS INTELLIGENCE DEVELOPMENT (by Stacia Misner)
6. Integration Services
7. Data Quality Services
8. Master Data Services
9. Analysis Services and PowerPivot
10. Reporting Services
You can download the PDF version of this title here (288 pages; 10.8 MB).
Happy learning.
PART I DATABASE ADMINISTRATION (by Ross Mistry)
1. SQL Server 2012 Editions and Engine Enhancements
2. High-Availability and Disaster-Recovery Enhancements
3. Performance and Scalability
4. Security Enhancements
5. Programmability and Beyond-Relational Enhancements
PART II BUSINESS INTELLIGENCE DEVELOPMENT (by Stacia Misner)
6. Integration Services
7. Data Quality Services
8. Master Data Services
9. Analysis Services and PowerPivot
10. Reporting Services
You can download the PDF version of this title here (288 pages; 10.8 MB).
Happy learning.
Microsoft Team Foundation Server - Antivirus folder rule out
Ozzie
Using corporate servers on a security aware organization implies that the IT governance policies enforce a network distributed and update antivirus software.
The bad news are that if a fine tuning and folder rule out policy is not in place, the database servers and application server will have their performance seriously compromised. The On-access scan feature will perform its own DoS attack on the hosts.
According to the server role, the adequate folder need to be ruled out from the malware scanning engine.On this specific post, you can find a lead on what folders should be ruled out on a Microsoft Team Foundation Server.
On the database server (MS-SQL) you should obviously rule out the path to the data volumes (.mdf and .ldf files) supporting the TFS.
On the actual TFS server, the following folder should be ruled out:
The bad news are that if a fine tuning and folder rule out policy is not in place, the database servers and application server will have their performance seriously compromised. The On-access scan feature will perform its own DoS attack on the hosts.
According to the server role, the adequate folder need to be ruled out from the malware scanning engine.On this specific post, you can find a lead on what folders should be ruled out on a Microsoft Team Foundation Server.
On the database server (MS-SQL) you should obviously rule out the path to the data volumes (.mdf and .ldf files) supporting the TFS.
On the actual TFS server, the following folder should be ruled out:
- C:\Program Files\Microsoft Team Foundation Server 2010
Mind that if you opted to setup the Team System Web Access on a different folder than the default, than that folder should also be ruled out from the On-access scan engine.
HTH.
5:14 PM
Programming
,
Systems Administration
,
tfs
,
Tools
Test open network ports using Powershell
Ozzie
Most frequently when deploying new scenarios, the task of network connectivity validation has to be performed.
Commonly this is performed using a command line and issuing a “telnet” connection to the desired host on a given port. This is nice when you have a single machine with a couple of connections to be tested.
When the scenario involves tens of machines with different network connection requisites between each other, the telnet procedure is a very slow process, being the typical test cycle:
To surpass these annoyances, one can use this Powershell function “Test-Port”, available from the Microsoft Technet Script Center Repository.
The syntax of the base usage is really simple. To test conecctivity to this site:
To address the fact of the ever growing shared network resources to be tested, an Excel spreadsheet can be used to generate the test battery script. Here’s an example you can view and download:
Afterwards, you just copy/paste the powershell column to a .ps1 file. I’ve also included a regular command prompt test column.
HTH.
Commonly this is performed using a command line and issuing a “telnet” connection to the desired host on a given port. This is nice when you have a single machine with a couple of connections to be tested.
When the scenario involves tens of machines with different network connection requisites between each other, the telnet procedure is a very slow process, being the typical test cycle:
- Open command prompt.
- Issue telnet to a given host and port.
- On success, close window and return to step 1.
- On failure, wait for timeout.
- Authorize the network port that failed
- Repeat step 2.
- On success go to step 1.
- Open command prompt.
- Issue command or script to test all destination hosts on desired ports.
- Check status and authorize failed network traffic.
- Repeat step 2 and check for success.
To surpass these annoyances, one can use this Powershell function “Test-Port”, available from the Microsoft Technet Script Center Repository.
The syntax of the base usage is really simple. To test conecctivity to this site:
Test-port -computer blog.ozzie.eu -port 80
To address the fact of the ever growing shared network resources to be tested, an Excel spreadsheet can be used to generate the test battery script. Here’s an example you can view and download:
Afterwards, you just copy/paste the powershell column to a .ps1 file. I’ve also included a regular command prompt test column.
HTH.
9:54 AM
Powershell
,
Systems Administration
,
Tools
Python, Oracle and LOB objects
Ozzie
The Python programming language is my preferred tool to develop quick and (sometimes) dirty scripts to perform single shot data processing tasks.
Recently, one of these tasks involved querying a table with a LOB column that stores XML strings. So the challenge was to read the LOB column and parse as string to dump the records to file.
My setup is Python 2.7 with the CxOracle 5.0.4 library. The first try I ran into the “LOB variable no longer valid after subsequent fetch” exception. According to the documentation this is because internally, Oracle uses LOB locators which are allocated based on the cursor array size. Thus, it is important that the data in the LOB object be manipulated before another internal fetch takes place. It also states that the safest way to do this is to use the cursor as an iterator.
Well, that’s all very nice, but I wouldn’t hang a cursor on a whole table, fetching the records one-by-one and processing the whole XML before going for another fetch. That’s not advisable on an OLTP database.
My solution and suggestion to other python users is to perform a two step fetch process:
Recently, one of these tasks involved querying a table with a LOB column that stores XML strings. So the challenge was to read the LOB column and parse as string to dump the records to file.
My setup is Python 2.7 with the CxOracle 5.0.4 library. The first try I ran into the “LOB variable no longer valid after subsequent fetch” exception. According to the documentation this is because internally, Oracle uses LOB locators which are allocated based on the cursor array size. Thus, it is important that the data in the LOB object be manipulated before another internal fetch takes place. It also states that the safest way to do this is to use the cursor as an iterator.
Well, that’s all very nice, but I wouldn’t hang a cursor on a whole table, fetching the records one-by-one and processing the whole XML before going for another fetch. That’s not advisable on an OLTP database.
My solution and suggestion to other python users is to perform a two step fetch process:
- Fetch all relevant primary keys from the table;
- Fetch the LOB column one-by-one using the PK list from the previous step.
def executaQueryLOB(txtQuery):
import cx_Oracle
orcl = cx_Oracle.connect('yourConnectioString')
curs = orcl.cursor()
curs.execute(txtQuery)
result=curs.fetchall()
strLOB=result[0][0].read()
orcl.close()
return strLOB
HTH.
4:04 PM
LOB
,
Programming
,
python
,
XML
Cartão de Cidadão – APIs de Desenvolvimento
Ozzie
De acordo com as notícias da actualidade, nomeadamente esta do Jornal de Negócios e esta da Semana Informática, as aplicações relacionados com os serviços da Administração Pública vão apostar fortemente na integração com o Cartão de Cidadão.
Esta aposta confirma-se com a publicação no Diário da República da Resolução do Conselho de Ministros nº.12/2012, de 7 de Fevereiro de 2012 que aprova o plano global estratégico de racionalização e redução de custos com as TIC na Administração Pública, apresentado pelo Grupo de Projeto para as Tecnologias de Informação e Comunicação (GPTIC).
Posto isto, é relevante fazer um levantamento do que existe actualmente que posa servir de base e acelerar o desenvolvimento da integrações do Cartão de Cidadão nas aplicações.
Numa pesquisa pouco exausta na Internet, aparecem os seguintes projectos:
O middlware do cartão é sempre necessário, de modo que na realidade apenas enumerei um projecto de terceiros que age com um wrapper .NET que expõe a API de interacção com o smart card.
Fica aqui o desafio de colocarem nos comentário a a esta mensagem algum projecto que conheçam ou usem e não esteja entre os referidos.
Esta aposta confirma-se com a publicação no Diário da República da Resolução do Conselho de Ministros nº.12/2012, de 7 de Fevereiro de 2012 que aprova o plano global estratégico de racionalização e redução de custos com as TIC na Administração Pública, apresentado pelo Grupo de Projeto para as Tecnologias de Informação e Comunicação (GPTIC).
Posto isto, é relevante fazer um levantamento do que existe actualmente que posa servir de base e acelerar o desenvolvimento da integrações do Cartão de Cidadão nas aplicações.
Numa pesquisa pouco exausta na Internet, aparecem os seguintes projectos:
O middlware do cartão é sempre necessário, de modo que na realidade apenas enumerei um projecto de terceiros que age com um wrapper .NET que expõe a API de interacção com o smart card.
Fica aqui o desafio de colocarem nos comentário a a esta mensagem algum projecto que conheçam ou usem e não esteja entre os referidos.
5:07 PM
cartão de cidadão
,
codeplex
,
Programming
,
Tools
Subscribe to:
Posts
(
Atom
)