SharePoint – Pass a Parameter as FILTER value to a Web Part

January 22, 2015

Click on the relevant Web Part -> Right Side -> Click on Hyperlink

Keep in mind EACH WebPart has a separate Data Source Field, Filter and Sort Settings !

clip_image002

clip_image004

First Create a New Parameter value based on a Query String Variable.

clip_image006

Next set the DVWP Filter settings

clip_image008

The result is that the data in DVWP will be filtered on load, by the Query String variable.

Second Example is to Filter a DVWP based on a Field value.

Based on the Query String Parameter you can filter the detail list web part for the items added.

clip_image002[1]

It will look like this. There is some garbage appearing on top of the DVWP ?

clip_image002[3]

Solution :

Just open the Form again in SP Designer and comment out that section to get rid of it.

<!--    
<tr>
    <td width="25%" class="ms-vb">
    <b>File Type:</b>
   </td>
.....
 <xsl:value-of select="@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico"/>
    </td>
</tr>     

-->

Look in the code for <!—…. –>

Filtering is quite handy !

Advertisements

SharePoint – Query String Parameters

January 22, 2015

In your development project you might need at some point in time to create a Query String Parameter.

But there are some challenges if you want to pass this to a Form Variable !

Here we go :

1. Create a Query String Parameter any string is fine.  and construct your URL.

http://server.com/Site/Lists/ListName/NewForm.aspx?HeaderID=23

2. Create a JQuery function for the receiving party.

$(document).ready(function() {

var lastId = $().SPServices.SPGetLastItemId({
    listName: "Sample_Header"});

var nextId = Number(lastId) + 1;
 //alert("Last ID " + lastId);

    $("#Details").click( function()
           {
                      alert("Next ID " + nextId );
     var URL = '/sites/Lists/Sample/NewForm.aspx?HeaderID=' + nextId ;
     alert ('We go to this ' + URL);
    window.location.href = URL;
           });
       });    

In this case we will use the parameter to filter a Data View Web Part. So add the script in the receiving Form to intercept is and pass it on to a Data View Parameter

3. Create the DVWP Parameter

In SharePoint Designer create a new Parameter

image

We call it as well HeaderID and refer to the Query String Parameter called HeaderID.

image

IMPORTANT :

This does NOT work for a Item Display Form a DVWP ?

Solution is to add this in the standard DISPLAY form NOT as a CUSTOM FORM.

image

But as a Display Item Form from the menu.

clip_image002

Don’t ask me why ?

For the other Forms (Edit and New) it does not seem to be a problem.

Best always test both ways in case of problems, anyhow.

In case you need to do some manual changes to the Forms.

Don’t use the Insert NEW Item Form from the MENU. Otherwise it goes wrong ?

Choose CUSTOM LIST FORM instead.

image

Choose for the list you need.

clip_image002[4]

So bottom line is that it is not so straight forward, to get the ball rolling Sad smile