SSRS Subscription ParameterValueOrFieldReference Default Value - c#

We have a .rdl file with parameters Available values coming from Query.
In the cascade drop down one of the parameter, we have set available values from query and also set default value -1
Screenshot
enter image description here
We are using reportinservice2010.asmx for creating subscription by passing parameters like below
List<ParameterValueOrFieldReference> parameters =
new List<ParameterValueOrFieldReference>();
parameters.AddRange(
rpt.ParameterNameMappings
.Where(p => p.IsMappingFieldAlias)
.Select(p => new ParameterFieldReference()
{
ParameterName = p.ParameterName,
FieldAlias = p.ParameterFieldAliasOrValue }));
parameters.AddRange(
rpt.ParameterNameMappings
.Where(p => !p.IsMappingFieldAlias)
.Select(p => new ParameterValue()
{
Name = p.ParameterName,
Value = p.ParameterFieldAliasOrValue }));
Above parameters we are using below:
rs.CreateDataDrivenSubscription(
report.FullName
, settings
, report.ReportSubscription.SubscriptionDataRetrievalPlan
, report.ReportSubscription.Description
, report.ReportSubscription.EventType
, report.ReportSubscription.MatchData
, reportParameters)
Problem : The subscription is getting created but the default values are not set in the screen of subscription edit. Other parameters which are not default are getting saved as Get Value from Dataset.
Solution : We need by default to set as "Use Default value"
enter image description here
Give solution to get use default values

Related

Value for ASPX Dropdown list is not being set to correct value

I am trying to bind a drop down list using this C# code:
var ctype = db.ComplaintTypes
.Select(r => new { r.ComplaintTypeID, r.Description })
.ToList();
ddlComplaintType.DataSource = ctype;
ddlComplaintType.DataTextField = "Description";
ddlComplaintType.DataValueField = "ComplaintTypeID";
ddlComplaintType.DataBind();
Code populates the dropdown however the index count is off by 1. So ComplaintTypeID has a value of 1 in the data table but the code is returning a value of 0. Which causing the app to crash for an invalid ComplaintTypeID.
If I add ddlComplaintType.Items.Insert(0, "** Please Select**");
It works but that causing my aspx required field validator to not work. How can I correct the code to show the correct datavalue ?

Field Not Recognized on AddAsync of SharePoint List Item

When I try to create a new list item with the basic calendar/list fields everything works perfectly. However, when I try to do so with a "non-standard" field i.e. a field I added, I am getting a "field not recognized" error.
The field is clearly there! Is there some special way I need to populate these custom fields?
// get a specific list
ISiteListsCollectionPage list = await graphClient.Sites["root"].Lists.Request()
.Filter($"DisplayName eq 'Outlook Integration'").GetAsync();
// create a dictionary of [calendar] list properties
Dictionary<string, object> props = new Dictionary<string, object>();
// populate properties, all of these work just fine
props.Add("Title", evt.Subject);
props.Add("Location", evt.Location?.DisplayName);
props.Add("EventDate", utcStart.ToString("yyyy-MM-ddTHH:mm:ssK"));
props.Add("EndDate", utcEnd.ToString("yyyy-MM-ddTHH:mm:ssK"));
props.Add("Description", Regex.Replace(evt.Body.Content, "<.*?>", String.Empty)); // remove HTML content
// populate custom properties
props.Add("ResourceID", evt.Id); // throws error: Field 'ResourceID' is not recognized
// create list item with our properties dictionary
var newItem = new ListItem
{
Name = "My New Event",
Fields = new FieldValueSet()
{
AdditionalData = props
}
};
// call the service and get the result
var newListItem = await graphClient.Sites["root"].Lists[list[0].Id].Items.Request().AddAsync(newItem);
This is the complete list of fields on my list:
Here you can see the display name is "ResourceID" whereas the API name is "O365EventId." However, both result in the same error, "Field not recognized."
Note: ResourceID is one of the fields that I added. How can I set the value of this field via the Graph API?
Marc is right by saying in comment regarding column name, the provided screenshot displays Column.displayName which is
The user-facing name of the column.
but what actually FieldValueSet.AdditionalData expects as a key is Column.name which is:
The API-facing name of the column as it appears in the fields on a
listItem. For the user-facing name, see displayName.
In your case most likely displayName and name properties are different, you could verify it via following endpoint:
https://graph.microsoft.com/v1.0/sites/root/lists/Outlook Integration/columns
and that's the reason why this error occurs.
Via the Graph API client (C#), you can see a list of all columns for any given list like so:
// get specific list by name
ISiteListsCollectionPage list = await graphClient.Sites["root"].Lists.Request()
.Filter($"DisplayName eq 'YOUR_LIST_NAME_HERE'").GetAsync();
// get columns and output them to the log as a serialized object
var listColumns = await graphClient.Sites["root"].Lists[list[0].Id].Columns.Request().GetAsync();
logger.LogInformation($"List Columns Object: {JsonConvert.SerializeObject(listColumns).ToString()}");

Can't edit my datagridview after binding to XML file via linq

Links to 2 similar examples on here which I can't really link to my exact case.
Similalr example 1
Similar Example 2
Here is the code that populates my datagridview...
XElement xdoc = XElement.Load(#"C:\xmltest\test.xml");
var lines = from item in xdoc.Descendants("line")
let fields = item.Elements("field")
select new
{
Name = (string)fields
.FirstOrDefault(n => (string)n.Attribute("name") == "Name"),
Description = (string)fields
.FirstOrDefault(n => (string)n.Attribute("name") == "Description"),
ExtraDetails = (string)fields
.FirstOrDefault(n => (string)n.Attribute("name") == "ExtraDetails"),
};
dataGridView1.DataSource = lines.ToArray();
This works fine but I can't edit the datagridview after the 'import'. I have defiantly set the datagridview settings to allow editing etc. The problem seems to be related to the databind in some way.
The problem is that you are projecting the result to anonymous type. The very first line in the documentation link states
Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first.
Hope you noticed the read-only word.
If you want to get editable data, then create your own class with read/write properties and project the query result into it.

How to insert 'Person or Group' field in list using VS2013?

I am using
string field = list.Fields.Add(StaticName, SPFieldType.User, true);
SPFieldUser user = new SPFieldUser(list.Fields, field);
user.AllowMultipleValues = allowMultiple;
user.Required = Required;
user.SelectionMode = mode;
user.LookupField = "Name";
user.Update();
code sample to create SPUser type of field.
It creates field perfectly fine but in default display value it gives employees' "Account" value instead of "Name" or "Name(with presence). How can I change this display value to "Name" pragmatically.
Thank you.
You can achieve this using two ways:
Just after the creation get the field again and use it (overcast) as SPFieldLookup field because SPUserField is child of SPFieldLookup:
SPFieldLookup userfield = (SPFieldLookup)list.Fields["fieldname"];
Userfield.LookupField = "ImnName";
Userfield.Update();
or you can create the field using AddFieldAsXml method like this:
list.Fields.AddFieldAsXml(#"<Field Name='TypeUser' ID='{99bd898d-c181-4ca9-8397-c9fc032fcdf9}' DisplayName='TypeUser' Type='User' ShowField='ImnName' ></Field>");
list.Update();
you should also take a look at Presence property and set it to true.

Dynamic default selected value for MVC DropDownList

I feel that the answer for this has to be out there in several places as variations of this question seem to get asked a lot. Unfortunately I cannot grasp exactly how to do what I am trying to achieve, so your help is greatly appreciated once again.
I have a list of usergroups, which are each assigned to a staff member. This is done by iterating through the list of usergroups and showing a dropdown of available staff members beside each one. It should be possible to not assign a staff member also, so a null value select option should be available.
When a new group is being created, having the null value as the default is fine, but where I am just updating an existing record, I want the dropdown to default to the option with the matching staff member ID.
So I query for available staff members:
var rtrnStaff = (from st in db.PrmTbl_Staffs
join sal in db.PrmTbl_Salutations on st.SalutationID equals sal.ID
where st.Active == true
select new { st.ID, Name = sal.Desc + ". " + st.Name });
To insert a blank value into this array:
List<SelectListItem> staff = new SelectList(rtrnStaff, "ID", "Name").ToList();
staff.Insert(0, (new SelectListItem { Text = "None", Value = "0" })); //can value be = null?
In my view, for the form to create a new user group, I can provide a dropdown like so:
#Html.DropDownList( "staffID", (IEnumerable<SelectListItem>)ViewData["StaffwNull"])
This provides a dropdown, with the "None" option first, which is fine. However, when I try the same thing for my update form, with the addition of a default value argument, it doesn't work:
#Html.DropDownList( "staffID", (IEnumerable<SelectListItem>)ViewData["StaffwNull"], item.StaffID)
The intention being that when placed within a foreach loop, the option matching the relevant staffID would show as default. Instead, "none" is still the first option.
I did try to just query the table in my controller, not build a selectlist there but pass the results directly via ViewData to the View, and then in the View do the following:
#Html.DropDownList("staffID", new SelectList(
(System.Collections.IEnumerable) ViewData["Staff"], "ID", "Name", item.StaffID),
new { Name = "staffID" })
That works no probs, but without a "none" option. Clearly I need some middle ground! Between DropDownList, DropDownListFor, List, SelectList, etc., I'm confused.
EDIT
(To show current state of code)
Controller:
var rtrnStaff = (from st in db.PrmTbl_Staffs
join sal in db.PrmTbl_Salutations on st.SalutationID equals sal.ID
where st.Active == true
select new { st.ID, Name = sal.Desc + ". " + st.Name });
List<SelectListItem> staff = new SelectList(rtrnStaff, "ID", "Name").ToList();
ViewData["StaffwNull"] = staff;
View:
//show dropdown of all staff,
//defaulting to "None" value (works)
#Html.DropDownList("staffID", (IEnumerable<SelectListItem>)ViewData["StaffwNull"], "None")
//show dropdown of all staff,
//defaulting to value matching item.staffID (doesn't work)
//default selection is first list item
//and list doesnt include "None" option
#foreach (var item in Model)
{
...
var thisStaffID = item.StaffID;
....
#Html.DropDownList( "staffID", (IEnumerable<SelectListItem>)ViewData["StaffwNull"], thisStaffID)
}
There is no overload where you can specify a selected value. MVC searches in the ViewBag object for an item called staffID and use that as selected value. You can use this overload of the DropDownList method which allows you to specify an option label:
#Html.DropDownList("staffID", (IEnumerable<SelectListItem>)ViewData["StaffwNull"], "None")
This renders an extra option to the select list at the top so you don't have to do this manually.
Side note: you should look into MVC model binding.
You can give an ID to the dropdown list (this overload) and then use jQuery to update it.
View
#Html.DropDownList("staffID", (IEnumerable<SelectListItem>)ViewData["StaffwNull"], new { id = "dropdown1" })
jQuery
<script>
$(document).ready(function () {
$('#dropdown1').val('theValueYouWantSelected');
});
</script>

Categories