Omit paramters in SSRS

Posted by Nadeem Yousuf | 05:36 | | 0 comments »

Scenario: Consider a report showing the name of the departments. However, there was a row which contained the text "Other" instead of department name. The requirement was to navigate to one report based on department name and other report based on text "Other".
Both the reports had same parameters except one parameter "headerName" which was present only in one sub report. So, we don't need to pass this parameter for that particular report.

Solution: Go to Textbox properties, select Action -> Go to report and locate the parameter which needs to be omitted. Click on the Omit button as shown:

By default the value is false, which means the parameter will not be omitted when calling a subreport. The value needs to be true in order for the parameter to be removed. The IIF condition can be used for omitting the parameter. In the below IIF condition, if the name of the DeptName field is not "Other", the "headerName" parameter will not be passed to the subreport. 

=IIF(Fields!DeptName.Value="Other",False,True)

 

Scenario: I had a report showing the name of the departments. However, there was a row which contained the text "Other" instead of department name and one row which contained the text "Firm-Wide". The requirement was to navigate to one report based on department name and other report based on text "Other". If the text was "Firm-Wide" no drill through action had to be performed.

Solution: The solution is to specify the drill through reports using IIF condition as shown in the screenshot:

=IIF(Fields!DeptName.Value="Firm-Wide", Nothing,
IIF(Fields!DeptName.Value="Other",
"TimekeeperTitlesMainCapacityReport",
"PracticeGroupMainCapacityReport"))



Scenario: You setup outgoing email settings in Central Admin and you also get the initial subscription alert for 
SharePoint list. Afterwards you don't get any mail on any further changes to the list.

Solution: Perhaps you are adding/modifying the list items by logging in as system account. Try logging in as any other user and modify the list and see if the alerts are coming up.

A user asked the following question:
I have SharePoint List with unique permissions. I need to retrieve the SharePoint Groups which don't have Full Control permissions on the List. Then need to remove them from the List Permissions only.
Since I was free I thought to give it a try. Following is the code:

ClientContext clientContext = new ClientContext("http://demo2010a:90");
            Web site = clientContext.Web;
            List list = clientContext.Web.Lists.GetByTitle("TestList");
            clientContext.Load(site, s => s.RoleDefinitions);
            clientContext.ExecuteQuery();
            clientContext.Load(list, l => l.HasUniqueRoleAssignments);
            clientContext.ExecuteQuery();
            List<Principal> groupsToRemove = new List<Principal>();           
            if (list.HasUniqueRoleAssignments)
            {
                RoleDefinition role = site.RoleDefinitions.GetByName("Full Control");
                clientContext.Load(role);
                clientContext.ExecuteQuery();
                RoleAssignmentCollection oRoleAssignments = list.RoleAssignments;
                clientContext.Load(oRoleAssignments);
                clientContext.ExecuteQuery();
                List<RoleDefinition> rolesToRemove = new List<RoleDefinition>();
                foreach (RoleAssignment oRoleAssignment in oRoleAssignments)
                {
                    clientContext.Load(oRoleAssignment, r => r.Member, r => r.RoleDefinitionBindings);
                    clientContext.ExecuteQuery();
                    Principal oPrincipal = oRoleAssignment.Member;
                    if (oPrincipal.PrincipalType == Microsoft.SharePoint.Client.Utilities.PrincipalType.SharePointGroup)
                    {
                        int roleDefCount = 0;
                        foreach (RoleDefinition def in oRoleAssignment.RoleDefinitionBindings)
                        {
                            if (def.Id == role.Id)
                            {                               
                                break;
                            }
                            else
                            {
                                roleDefCount++;
                                if (roleDefCount == oRoleAssignment.RoleDefinitionBindings.Count)
                                    groupsToRemove.Add(oPrincipal);
                            }
                        }                     
                    }
                }

                foreach (Principal group in groupsToRemove)
                {
                    list.RoleAssignments.GetByPrincipal(group).DeleteObject();
                }

                list.Update();
            }

            clientContext.ExecuteQuery();

I actually tried to use a simpler statement i.e.

 if (!oRoleAssignment.RoleDefinitionBindings.Contains(role))
 {
       groupsToRemove.Add(oPrincipal);
 }
But it gives follwoing error: Invalid usage of query execution. The query should be executed by using ExecuteQuery method on the client context object. Anyone having idea why this error comes up?

I had a following code snippet which deleted items in a SharePoint list using Batch Delete method.

private static StringBuilder BatchCommand(SPList spList)
        {
            StringBuilder deletebuilder = new StringBuilder();
            deletebuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
            string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
                "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";

            foreach (SPListItem item in spList.Items)
            {
                deletebuilder.Append(string.Format(command, item.ID.ToString()));
            }
            deletebuilder.Append("</Batch>");
            return deletebuilder;
        }

The above method was called from the main function like this:

using (SPSite spSite = new SPSite(site))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {
                    StringBuilder deletebuilder = BatchCommand(spWeb.Lists[list]);

                    spSite.RootWeb.ProcessBatchData(deletebuilder.ToString());
                }
            }
But to my surprise it was not deleting any item in the document library. In order to make sure that the above code is correct I ran it across a custom list and it worked well. After some searching I found that owsfileref also needs to be added in the xml request.

<SetVar Name=\"owsfileref\">{1}</SetVar>
Here is the modified code for bulk deleting items in Document Library:
private static StringBuilder BatchCommand(SPList spList)
        {
            StringBuilder deletebuilder = new StringBuilder();
            deletebuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
            string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
                "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"owsfileref\">{1}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";

            foreach (SPListItem item in spList.Items)
            {
                deletebuilder.Append(string.Format(command, item.ID.ToString(), item.File.ServerRelativeUrl));
            }
            deletebuilder.Append("</Batch>");
            return deletebuilder;
        }
  

I setup a content source to include my site and did a full crawl and everything went fine without errors.
But then search was not returning any results. 
In the central administration site I found that service application associations were not correct for the given web application as shown in the screenshot:













As is clear from the screenshot FAST Query was selected by default whereas I needed Search Service Application. After making the changes the search started working but now it was giving results only for the admin accounts and not for other users with proper permissions. It turns out that  Search service account needs to be added to  "Windows Authorazation Access Group" as can be seen from this article.

A user asked a question about changing the display name of a field in a SharePoint list and make it a required field using CSOM (SharePoint 2010 Client object model). Here is how it can be done:

ClientContext clientContext = new ClientContext("http://demo2010a:90"); List list = clientContext.Web.Lists.GetByTitle("Products"); clientContext.Load(list); clientContext.ExecuteQuery(); var fields = list.Fields; clientContext.Load(fields); clientContext.ExecuteQuery(); var field = fields.GetByInternalNameOrTitle("Status"); field.Required = true; field.Title = "StatusB"; field.Update(); clientContext.Load(field); clientContext.ExecuteQuery();