Thursday, February 16, 2012

SPMetadata - SharePoint metadata query facilitation

While developing custom field types I found out that I often had to make queries to different metadata of different sites via different identifiers. For example, a list can be identified via both site-relative URL and ID. And if you want to get it according to Best Practices: Using Disposable Windows SharePoint Services Objects, you will have to determine SPSite and SPWeb identifiers which can be different.

It was necessary to get rid of these annoying dilemmas in order to be able to focus on developing of custom field types.


Sunday, February 5, 2012

SharePoint Extended lookup field. Part 2: Value display in ListViewWebPart using jQuery+JSON

In the first article of the blog I wrote about displaying field values in (Render Pattern) Display Pattern using web-services and JavaScript. This method is good enough… However, if we have large volume of data to display the productivity will be low. The reason is that every time field value isn’t filled a web-service is called and a wsdl answer is parsed. Probably this method of displaying values by this type of field can satisfy an end-user it’s unlikely that metadata field will be widely used). However, it won’t work with Extended Lookup Field.

The first idea for automation is a onetime call of a web-service to transfer an array of nonrecurring field values. And it’s better to choose another data format instead of XML. Using jQuery is one of the best ways to select necessary items on a HTML page. Choosing this framework it’s better to send and receive data in JSON format. Moreover there are all necessary metadata for it in NET Framework 3.5 SP1.

As far as web-service call will be made only once it’s better to make this via element event in HeaderPattern.  Such element will be iframe element with onload event. A part of the HeaderPattern code for this decision is given below.
<RenderPattern Name="HeaderPattern">
  <HTML><![CDATA[<script src="/_layouts/jQuery/jquery-1.6.4.js"></script>]]></HTML>
  <HTML><![CDATA[<script src="/_layouts/jQuery/json2.js"></script>]]></HTML>
  <HTML><![CDATA[<script src="/_layouts/ExtLookup.js"></script>]]></HTML>
  <HTML><![CDATA[<iframe id="Header]]></HTML>
  <List/>
  <Property Select="Name"/>
  <HTML><![CDATA[" height="0" width="0" onl oad="GetExtValueAJAX(&quot;div_]]></HTML>
  <List/>
  <Property Select="Name"/>
  <HTML><![CDATA[&quot;, &quot;]]></HTML>
  <HttpVDir/>
  <HTML>
    <![CDATA[&quot;, &quot;]]>
  </HTML>
  <List/>
  <HTML>
    <![CDATA[&quot;, &quot;]]>
  </HTML>
  <Property Select="Name"/>
  <HTML>
    <![CDATA[&quot;);"></iframe>]]>
  </HTML>
</RenderPattern>