I wrote a little C# app to retrieve data from several SP custom lists. This has been going very smoothly for months. Now I updated my app to alter some items. To be exact I like to update one multiline text field for some items. Here is my code:
// Update SharePoint list elements
foreach (var o in toWrite) // List<(int, string)>();
{
List destList = ctx.Web.Lists.GetByTitle(listToUpdate); // listToUpdate: SP list name
ListItem listItem = destList.GetItemById(o.Item1); // o.Item1: id to update
listItem[fieldToUpdate] = o.Item2.ToString(); // o.Item2: new string for plain text multiline field
listItem.Update();
ctx.ExecuteQuery();
}
The ExecuteQuery() fails with an error "Invalid request."
Writing a single line text field with max. 255 chars this method works fine, so I assume that for multiline text fields I need to somehow handle this long strings in another way. Unfortunately I couldn't find any suitable FieldValue classes in the API.
I would appreciate any help.
What's the detailed characters for updating the multiple line text field ?
I tested the code snippet, it's working to update the field:
ClientContext ctx = new ClientContext("http://sp/sites/MyDev");
Web web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
List list = web.Lists.GetByTitle("MyList");
ListItem item = list.GetItemById(1);
item["Note"] = "TestCharacter";
item.Update();
ctx.ExecuteQuery();
Jerry_MSFTs code as well as mine work fine. The issue with SharePoint Online is that requests will fail when the custom field you like to update is named "Properties". After creating a field with another name everything works smoothly.
Related
I am trying to search for appointment on a shared calendar. The first step is I am saving the appointment in shared calendar with a custom property twMeetingId. This is working fine:
Outlook.AppointmentItem nurseAppointment = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Add();
nurseAppointment.UserProperties.Add("twMeetingId", Outlook.OlUserPropertyType.olText, false, 1);
nurseAppointment.UserProperties["twMeetingId"].Value = appointmentData.meetingId;
nurseAppointment.Save();
Then I am trying to find any appointments in the same shared calendar based on the custom property twMeetingId
var filter = $"#SQL =\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/twMeetingId/0000001f\" = '{appointmentData.meetingId}'";
Outlook.Items items = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Restrict(filter);
At this point I am receiving an error "Condition not valid". I have checked the meetingId value is correct in the filter. I have also tried to use Jet query as below but it also does not work:
nurseAppointment = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Find(String.Format("[twMeetingId] = '{0}'", appointmentData.meetingId));
What am I missing here?
You have an erroneous space between #SQL and =. The following condition worked without error for me:
#SQL="http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/twMeetingId/0000001f" = 'test'
Also make sure appointmentData.meetingId does not contain any characters that need to be encoded.
Looks like you have got a wrongly composed search string in the code:
var filter = $"#SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/twMeetingId\" = '{appointmentData.meetingId}'";
First, as you can see you need to use a single curly braces in the search string.
Second, you need to remove the property type in the end of DASL property name.
If you want to use the property name without DASL namespaces like that:
"[twMeetingId] = '{0}'"
You need to make sure the property is added to the folder fields when you call UserProperties.Add method. The AddToFolderFields parameter is true if the property will be added as a custom field to the folder that the item is in. This field can be displayed in the folder's view. alse if the property will be added as a custom field to the item but not to the folder. The default value is True.
You may find the Filtering Items Using Query Keywords article helpful.
okay, it seems that no one is explaining the process of this issue completely, even kentico's documentations are not well organized and clear. My problem is that i have more than 50 records in a table in SQL which i would like to load in a single ASP dropdown list (because it would be a bad practice to fill it statically), and I am new to kentico so my problem is that I need a complete explanation about the process from A to Z, from building the query in kentico, to using it in visual. please post some examples if possible.
also please note that i have seen many examples like this one:
https://docs.kentico.com/k10/custom-development/developing-web-parts/advanced-web-part-development-scenarios/developing-custom-filters
but these examples are showing us only the last step, which is using DepartmentInfoProvider.GetDepartments(); to fill the dropdownlist, my main focus is to know how and where and using what they created the DepartmentInfoProvider class on the first place.
you should read about creating custom modules. There is a section how to add a class to the module. As soon as you add a class to the module, you'll be able to generate its Info and InfoProvider class, then add these files to solution and use them.
Farah, Another person asked a similar question:
https://devnet.kentico.com/questions/custom-filter-with-a-drop-down-list-from-the-databse
This will help give a little info on the Info and InfoProviders in Kentico
To be more specific to your needs though, you can use the QueryInfoProvider.ExecuteQuery to use a custom Kentico query that selects from your table, OR you can as Anton suggested make a custom module, but if you're new to Kentico this may be a bit much for you.
Lastly, if you want i have a universal filter webpart (just haven't published it yet) which gives you the ability to simply write a SQL query and then define how that selected value affects your repeater (you design the WHERE condition). Just tell me if you want it.
The solution was far more simple than I thought, First we should create a Query in Page Type --> Queries --> new Query --> specify queryName and queryText, the query gets the data from database, second in visual we have to write:
using System.Data;
private void initializeDropDownList(String queryName, String rowName, DropDownList dd)
{
List<String> listData = new List<String>();
DataSet dataset = new DataQuery("custom.PageType." + queryName).Execute();
foreach (DataRow row in dataset.Tables[0].Rows)
{
listData.Add(row[rowName].ToString());
}
String[] arrayData = listData.ToArray();
foreach (String data in arrayData)
{
if (data.Equals("")) { continue; }
else
{
dd.Items.Add(new ListItem(data));
}
}
}
Thanks for reviewing my question. Basically, in my form... The manager can set a reminder to an employee, so when the employee logs into my form... it comes up with a reminder from the manager.
Trouble is, the data contains multiple reminders from the same user but when I add them to a text box I get this error:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Core.dll
Additional information: Sequence contains more than one element
my code:
System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["Login"];
int id = Convert.ToInt32(((Login)f).idTb.Text);
SundownDatabaseEntities4 db = new SundownDatabaseEntities4();
var getrecord = db.Reminders.Where(a => a.Id == id).SingleOrDefault();
reminderTb.Text = Convert.ToString(getrecord.Reminder1);
How do I add multiple elements to a text box? Could I use a list box?
It sounds like you are trying to append multiple different strings to a single textbox, which in this case i would use the appendText() extension on the textbox to add multiple strings. You could also use the ListBox if you would like. I would set the Source to the data you are sending it for ease of use.
Here is a link to the append text function
https://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.appendtext(v=vs.110).aspx
Here is a link to how to set-up a source for a listbox
https://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.datasource(v=vs.110).aspx
Edit
To add on since it was something else causing the issue I would use:
List<object> objects = Enumerable.Select(i => i.id == id);
Here is a link to the msdn for more information
https://msdn.microsoft.com/library/bb548891(v=vs.100).aspx
Edit 2
After finally getting my VS up to date and playing around i think the easiest thing you can do here is:
db.Reminders.ForEach(reminder => {if(reminder.Id == id){ reminderTb.AppendText(Convert.ToString(reminder.Reminder1)); }})
You might need to adjust accordingly to your specific code not sure if i have your class structure right, but this will look through the array of reminders, look and on that specific id it will append the text to the text box with what I imagine is what you wanted based off your code and the class structure i saw. this should work since you are manually going through the array and adding the text.
We are using Sitecore 8 update-5. We would like to check which values changed in a specific field during a publish. For this we are subscribed to the item:saved event handler. When extracting the ItemChanges parameter from the event arguments we use the FieldChanges property for that field. In the master database the FieldChanges dictionary contains only those fields that were changed and FieldChanges.OriginalValue and FieldChanges.Value contains the proper values (the old ones and the new ones). However when publishing from master to web DB it seems that the FieldChanges always contain all fields and the OriginalValue and Value properties are always the same. We tested this with items which were already existing in web database, using smart publish and a single language.
The question is this is how it should work or is this a bug?
Some example code:
var topicFieldID = new ID(RelatedTopic.FieldIDs.Topics); //getting the field ID
var changes = Event.ExtractParameter<ItemChanges>(args, 1); //in item:saved event handler
var oldIDs = changes.FieldChanges[topicFieldID]?.OriginalValue?.ToString().Split('|');
var newIDs = changes.FieldChanges[topicFieldID]?.Value?.ToString().Split('|');
and in our case the "oldIDs" and "newIDs" contain the same values in web DB
Regards,
Chris
I'm currently doing a little bit of upgrading to a solution 3 upfates of which are display name changes.
I have 3 fields
A date field Approved - Required
A date field expiry - Required
Number - Not Required
I update these fields display names at site level and push the changes down.
The result is that all fields are updated at site level.
Only the Number field gets updated in the site content types.
I'm not getting anything back from the ULS logss, Is this a special feature of SharePoint that you can't update the display names of required fields programmatically?
private void UpdateFieldDisplayNameAndDescription(SPSite site, string fieldStaticName, string newFieldDisplayName, string description, bool isRequired)
{
try
{
using (SPWeb web = site.RootWeb)
{
SPField field = web.Fields.TryGetFieldByStaticName(fieldStaticName);
if (field != null)
{
field.Title = newFieldDisplayName;
if (!string.IsNullOrEmpty(description))
{
field.Description = description;
}
field.Required = isRequired; // Tried this method without this here also.
field.PushChangesToLists = true;
field.Update(true);
}
}
}
Any Ideas
My next step is to make sure that this is also replicated to any content types within lists but don't want to try that until this little niggle is sorted. Any ideas or tips?
I am running this under a custom action(feature upgrade)
I believe the reason for the push down not working for the two required fields is because the XML that defines them has been updated in the projects lifespan, The Number field that was updating correctly has never been changed.