Tuesday, November 23, 2010

Rich Text Column in Document Library

WSS – Rich Text column in Document Library

Being not able to add a rich text column to a document library, is frustrating as I wanted to use the column to hold rich text. It is possible to use a rich text column in a doc library but it must be done using a content type, Here are some instructions below on to get a document library setup with a rich text column:
  1. Configure ‘Advanced Settings’ for the document library and enable the management of content types.
  2. Create a new Site Column as multiline rich text.
  3. Create a new Content Type and add the column created in step 2.
  4. Add the Content Type to the document library using the ‘Add from existing site content types’ link.
  5. Save the document library as a template and delete the document library.
  6. Create the document library again using the template from step 5.
  7. Success! You should now be able to use a rich text column within a document library.
Thanks:  http://sharepointcoding.wordpress.com/2009/05/28/wss-rich-text-column-in-document-library/

Monday, November 22, 2010

List - Update Columns behind the screen based on other columns

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("populateFieldvalues");

    var populate = getField('select','Current Status');
    populate.onchange = populateFieldvalues;

    function populateFieldvalues() {
        var control = getField('select','Current Status'); //Based on the Value of this 'Current Status', Status &Description will be changed. Ex: If yellow is selected for 1 column, other column named Status, its URL and Desc would be changed accordingly.
        var Statusurl = getField('input', 'Status');
        var Statusdesc = getField('input', 'Description');

        if (control.options[0].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/white.gif";
            Statusdesc.value = "White";
            }
           
        else if (control.options[1].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/green.gif";
            Statusdesc.value = "Green";
            }

        else if (control.options[2].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/yellow.gif";
            Statusdesc.value = "Yellow";
            }
           
        else if (control.options[3].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/red.gif";
            Statusdesc.value = "Red";
            }

        }

    function getField(fieldType,fieldTitle) {
           var docTags = document.getElementsByTagName(fieldType);
        for (var i=1; i < docTags.length; i++) {
            if (docTags[i].title == fieldTitle) {
                return docTags[i];
            }
           }
    }
   
</script>

Friday, November 19, 2010

Creating and Customizing Document Information Panel with Infopath 2007



Document Information Panel

Announcements ListView WebPart - Modifying View

Using Sharepoint Designer, change the existing listView to XSL DataView and then change the following to modify the view:

<xsl:template name="dvt_1.rowview">
        <p class="ms-vb">
             <a href="http://YourServer/sites/Dev1/Lists/NameOfList/DispForm.aspx?ID={@ID}"><xsl:value-of select="@Title" /></a>
            <br />By
            <xsl:value-of select="@Author" disable-output-escaping="yes" /><br />
            <xsl:value-of select="@Body" disable-output-escaping="yes" /></p></xsl:template>






Wednesday, November 17, 2010

Bulk Update List Items using JQuery WebService

Querying and Updating the List

(1)Add a CEWP on any default.aspx page [Not on any of the List view pages]
(2)Copy paste the code and change URLs for List and Site along with Column names that you want to Update with
(3) 2 functions btnPublishAll() - Gets each List items ID's and Title  and fxnPublishList() - Updates each List item's PublishColumn to Published.
(4)Add your list(YourListName) webpart on the same page, so that Button to bulk publish all items for the List and List would be on the same page.


<script type="text/javascript">

$(function($){
        $("#btnPublishAll").click(function(){
           var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>YourListName</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='ID' /> \
                               <FieldRef Name='Publish' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: "http://YourServer/sites/Dev1/myDev1/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        }); // end $.ajax()

                function processResult(xData, status) {
                     $(xData.responseXML).find("z\\:row").each(function() {
                     //Here you get the ID's of each Item in the List and we can call Update function using these ID's
                      var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>"; //To Display each List items Title in a row
                      //$("#TestUL").append(liHtml);
                       fxnPublishList( $(this).attr("ows_ID"), "Published" ) ;
                        window.location="YourPage"; //To Refresh the page after the Update.
                                   
                  });
                } // end processResult
                                               
                                               
   }); // end click
  
 
  
}); // end ready

function fxnPublishList(ItemID,ItemNewValue)
{
    var soapEnv =
        "<?xml version='1.0' encoding='utf-8'?> \
            <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>YourListName</listName> \
                        <viewName>AllItems</viewName> \
                        <updates><Batch OnError='Continue' PreCalc='TRUE'> \
                               <Method ID='1' Cmd='Update'> \
                                  <Field Name='Publish'>" + ItemNewValue + "</Field> \
                                  <Field Name='ID'>" + ItemID + "</Field> \
                               </Method> \
                        </Batch></updates> \
                    </UpdateListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";
   
    $.ajax({
        url: "http://YourServer/sites/Dev1/myDev1/_vti_bin/lists.asmx",
        beforeSend: function(xhr){ xhr.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");},
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        contentType: "text/xml; charset=\"utf-8\""
    }); // end $.ajax()
}


</script>
<p/><p/>
<input type="button" id="btnPublishAll" value="Publish All" />


Reference:  Link to Jan Tielens Blog for querying list items.

Tuesday, November 9, 2010

Build URL for webservices Ex: Lists.asmx

 var hrefParts = window.location.href.split('/');
            var wsURL = "";
            for (i = 0; i < (hrefParts.length - 2); i++) {
                if (i > 0)
                    wsURL += "/";
                wsURL += hrefParts[i];
            }
            wsURL += "/_vti_bin/lists.asmx";

Remove *Title Column in a Sharepoint List

SharePoint List items all have a Title column (although it’s display name might be changed to something else). This Title column is a string, which is unfortunate as sometimes you really don’t need a string column on a list; this was the need I faced.
You can make a Title column not required:
turn-off-title-requirement
Also, if you go to the ‘Advanced Settings’ page of your list and ‘Allow management of Content Types’ you can then go into your content types and Hide the Title column. This is okay – but the Title column is still there – it’s just being displayed with “(no title)”…
List View Showing Title
That’s not such a problem for views on a list – you can simply choose to not show the Title column. But unfortunately, some other pages (such as EditForm.aspx and DispForm.aspx) use the Title column in their title and navigation:
original-edit-form
“(no title)” sucks a bit, especially as we probably do have something better to use as a title. I decided to use jQuery to replace the “(no title)”s in the Edit and Display forms:
code
Or, as text:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var user = $("span[class='ms-entity-resolved'] > span[id='content']");
var userText = user.text();
document.title = "Users - " + userText;
var pageTitle = $("h2[class='ms-pagetitle']");
var pageTitleHtml = pageTitle.html();
pageTitle.html(pageTitleHtml.replace("(no title)",userText));
var pageLink = $("td[class='ms-titlearea']");
var pageLinkHtml = pageLink.html();
pageLink.html(pageLinkHtml.replace("(no title)",userText));
});
</script>

Here I’m getting the new title from my user field – but you might want to use another field. Whatever, the same principle of using jQuery to get the value would work.
Then I update the Browser’s title bar with the new title.
Next, I select the page title and replace “(no title)” with my new title, before writing the html back, and finally I repeat this with the “(no title)” link in the breadcrumb. The end result is:
modified-edit-form
Nice. I repeated this for my Dispform.aspx too, though not the new Item form – it doesn’t display the title at all (as a new item doesn’t have one yet!) I also added an edit button to my list so that users can still edit these items:
modified-list-view
(And yes, there are other ways of dealing with this – building  proper custom edit and display forms, for example – but this is quite low effort)

Reference:  http://www.novolocus.com/2009/06/02/using-jquery-to-remove-the-title-of-a-list/