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.
Related
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.
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 fairly new to asp mvc and I'm currently trying to limit the text on an item in my site, how can i limit the text for:
#Html.DisplayFor(model => model.Text)
I have tried just creating another item in the model like this:
public string Text {get; set; }
private string _limitText;
[StringLength(30)]
public string limitText
{
get
{
return (_limitText = this.Text)
}
set
{
_limitedText = Text;
}
}
However i get errors when updating database with the Nuget Console:
"String or binary data would be truncated. the statement has been terminated"
All help appreciated.
It seems you are using EF code first and trying to upgrade your DB using code first migrations.
Since you have already created table with VARCHAR(MAX) length (If you do not specify length on your property it will be considered as max length by EF), you will need to first delete all records from DB which has length more then 30 for limittext column. Else you wont be able to upgrade your version using code first migration.
If you do not want to loose your data then clone your table and then migrate your database and then copy your data back to original table.
You can clone table using following query
SELECT *
INTO CustomerClone
FROM Customer
Your chief problem here is that your new property, limitText has both a getter and setter and you're filling it with the full text from Text. If a property has a getter and setter, then Entity Framework persists it to the database. That alone is probably not ideal, since you're basically duplicating data, but let's say you wanted it to actually be persisted. It's value is set to the full string of Text, but it's going to then be persisted into a column that has a maxlength of 30 characters, hence the error. There's many ways to fix this problem. First, you can simply set the value to just the truncated string:
_limitText = this.Text.Substring(0, 30);
Then, it will save fine because the value will always be 30 characters of less. However, more likely than not, you simply shouldn't persist this field. That can be accomplished by either 1) removing the setter or 2) decorating the property with [NotMapped].
Also, you could simply not use this extra property at all. There's no need to use Html.DisplayFor here, so you could simply just do the following in your view instead:
#Model.Text.Substring(0, 30)
There are simple 2 ways how the issue can be solved:
First, you can use attribute maxlength to specify maximum length of the text that can be input. In this case you need to change DisplayFor to TextBoxFor and use maxlength attribute:
#Html.TextBoxFor(model => model.Text, new { maxlength=30 } )
Second, you can take first 30 symbols of the property by using Substring function. This is not very nice approach but it works.
So I have a very simple Coded UI Test in Visual Studio 13' that simply visits my web page, logs in, and then clicks on a menu item that directs it to a table. During different times, that table may be empty or may be full of data. All I want to do is simply grab the 'id' attribute of the table and make assertions about its row count. Using C#, what is the easiest way to do this? I've researched and it looks like HtmlControl(s) are a possible solution (like the example here) but I can't seem to get the result I want. Thanks!
You can use this:
public HtmlEdit TbxUserName
{
get
{
if ((tbxUserName == null))
{
tbxUserName = new HtmlEdit(browser);
tbxUserName.SearchProperties[HtmlControl.PropertyNames.Id] = "UserName";
}
return tbxUserName;
}
}
There can by problem in webforms if you have generated ids, but it can be done with 'contains':
divMarketMap.SearchProperties.Add(new PropertyExpression(HtmlControl.PropertyNames.Id, "someId", PropertyExpressionOperator.Contains));
This is a bit of a longshot but here goes...
I am currently working on a project that interfaces with Microsoft CRM 2011 via its XRMServices.
My problem is that certain money (a.k.a Currency) values are updated in the [AccountBase] table whilst others are not. The [revenue] field is updated, but the [aging30] value is not. Both of these field share the same major properties:
The are both of Type Currency
They are both default fields.
They both dont seem to have any database constraints on them.
!! [aging30] seems to be read only however !!
What could be causing this despite the fact that the field might be read only? I thought that I might have something to-do with the field level security or user security, but that does not seem to be it. I have sufficient rights on the system and the field properties are not set to disable such actions.
The only other thing I could think of is that it might be a workflow that is prohibiting me from updating this value, but once again I could not see anything in the system that seems related to this point. After running the code below the entity is revenue value is updated and is visible in dbo.AccountBase, but the [aging30] field is not. No exception is generated by the XRM web service.
Figure 1 - Retrieving the account
public Entity GetByAccountCode(string accountCode, bool allColumns = false)
{
if (string.IsNullOrEmpty(accountCode))
return default(Entity);
QueryExpression query = new QueryExpression("account");
query.ColumnSet = new ColumnSet(allColumns);
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("accountnumber", ConditionOperator.Equal, accountCode);
EntityCollection results = _service.RetrieveMultiple(query);
if (results.Entities.Count == 0)
return default(Entity);
if (results.Entities.Count > 1)
throw new DuplicateRecordsOnAccountCodeException(accountCode, "Duplicate records on AccountCode found"); // needs to be changed appropriatly
return results[0] as Entity;
}
Figure 2 - Updating the account**
account.Attributes["revenue"] = new Money((decimal)100m); // This value is updated
account.Attributes["aging30"] = new Money((decimal)200m); // This value is not
_service.Update(entity);
Based on SDK this field (aging30) is a platform and valid only for read.