I am trying to update an object (Generic List object) to RuntimeFiledCollection. When I try to update using the following code, I am getting always Serialization error :(
//My object which need to update set with the documentRuntimeField value
List<docInfo> docInfoList = new List<docInfo>
docInfo = new docInfo { ID = "11233", PageNumber = 1, text ="MyOwnText"};
docInfoList.Add(docInfo);
// Construct DOcument RuntimeFields Collection
var docRunTimeCollection = new CaptureDocumentService.RuntimeFieldCollection();
var docRunTimeField = new CaptureDocumentService.RuntimeField
{ Name = "FieldName", Value = docInfoList };
docRunTimeCollection.Add(docRunTimeField);
captureDocumentServiceClient.UpdateDocumentFieldValues(sessionId, null, validDocumentId, docRunTimeCollection);
I always get sterilization error as shown below. Can someone give me an example how to update document field values with an object. Any help ?
Error : There was an error while trying to serialize parameter http://www.kofax.com/agilityservices/sdk:runtimeFields.InnerException message was System.Collections.Generic.List
For RuntimeField class, you can see the the Value property is of type Object, but that is misleading, because it is not an arbitrary container. It takes the type that you defined for that field in your Extraction Group. But essentially that just means it will take a DateTime for a Date field or numeric types for a Number field, and anything else would be casted to string.
If you actually using a Table Field, then you cannot use the API to set the contents of the entire table. You would instead set the RuntimeField.TableRow and RuntimeField.TableColumn properties to use the API to set individual cells.
Related
I'm trying to set the value of a custom radio button field that has 3 possible options: Yes, No or none. I'm using the Dapplo c# Jira SDK.
I've tried everything going from using "name" to "value" to "id" but nothing seems to work, I always get back "Could not find valid 'id' or 'value' in the Parent Option object".
Note that I want to set the field value by using the ID of the optionset value, not the textual value (like Yes or No) as that might change over time.
These are some of my attempts:
string jsonString = #"{""id"": ""11684""}";
var myJSON = JsonConvert.SerializeObject(jsonString);
issueToCreate.Fields.CustomFields.Add("customfield_12093", jsonString); //When I enter the 'jsonString' variable directly I get the same error.
does anyone have any idea? This seems much harder than it should be..
After trying about everything, the following finally worked:
var optionSetObject = new { id = "11681" };
issueToCreate.Fields.CustomFields.Add("customfield_12093", optionSetObject);
I thought the c# anonymous object wouldn't get serialized correctly, but apparently it does. Make sure the "id" value is a string though! If you enter it as an int, Jira won't recognize it for some reason.
You can try: (like use JavaScriptSerializer to serialise an anonymous object):
var optionSetObject = new { id = "11681" };
var serializer = new JavaScriptSerializer();
var output = serializer.Serialize(optionSetObject);
issueToCreate.Fields.CustomFields.Add("customfield_12093", output);
I am assigning property names of a dynamic object as ints in string form. The int value represents an int ID in a database I am using. However I am stuck on how to retrieve the value assigned to the property as shown below:
dynamic test = new ExpandoObject()
IDictionary<string, object> proxyFiler = test as IDictionary<string, object>;
proxyFiler["four"] = 4;
proxyFiler["5"] = 5;
int r = test.four; // Works
int s = test.5; // Doesn't work
A method which reads the database will return an "int" and I would like to be able to access the property value with that property name.
To expand on this: what if I wanted to do a linq query to sort out a list of dynamic objects according to a property name? In this case I need to get the propertyName which I have retrieved as a string e.g. "15":
return disorderedList.OrderBy(o => o.propertyName).ToList();
Does anyone know a simple solution to this problem or do you recommend a different approach? Thanks.
In order for dynamic to work in this way, the key has to follow the rules for valid identifier names in C# (the rules are specified in this outdated MSDN page, but also in the C# language specification). A single number (5) is not an allowed identifier name, which is why that doesn't work.
Note that you can still retrieve the value by using the type as a dictionary, in a similar manner to how you populated it.
As for your second example - you are never using value, so it has no effect. It's the same as just writing int r = test.four;
Edit:
I believe, given your approach, you'd need to cast to a dictionary:
return disorderedList
.OrderBy(o => ((IDictionary<string, object>)o)[propertyName]).ToList();
when I try to cast a list item as an object, I get the following. "Cannot convert type 'System.Web.UI.WebControls.ListItem' to 'ASPGigManager2.GigOpportunity'"
Is there anyway you can do this? Here is my code:
GigOpportunity gigOpportunity;
gigList.removeGig((GigOpportunity)lstGigs.SelectedItem);
I have tried to go the long way round and convert it to string but I still get a conversion error, string to GigOpportunity.
GigOpportunity gigOpportunity;
string test;
test = Convert.ToString(lstGigs.SelectedItem);
gigOpportunity = test;
Its as it says, you cannot convert a ListItem to GigOpportunity. And since this is ASP.NET, your original object no longer exists inside the list control. So, during your initial binding, set the DataValueField property to a unique value that identifies each gig (such as a primary key).
Then, on a callback, you have to find your original gig again. For example:
var selectedValue = lstGigs.SelectedValue;
var gig = gigList.Where(x => x.SomeKeyValue == selectedValue).Single();
gigList.Remove(gig);
Better yet, turn you gigList into a dictionary who's key is the same key you used as the value. Then, all you have to do is
gigDict.Remove(lstGigs.SelectedValue);
I have the following code:
var db = Database.Open("Text");
var headers = db.Query("SELECT * FROM Headers");
//headers is now an IEnumerable<dynamic>
string s = headers[0].Text; // Works correctly
headers[0].Text = "Some string";
If I try to assign "Some string" to the Text property of the headers I get the following error:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: WebMatrix.Data.DynamicRecord contains no definition for Text.
How can I convert the headers object to a List/Array so that I am able to assign new values to it?
The problem is that the DynamicRecord class being returned from WebMatrix is effectively 'read-only'. The DynamicObject does not allow setting of Text.
You would need to map this data onto your own classes if you want to make changes to the values, and not leave them within the original dynamic type.
My question relates to programmatically writing to a Sharepoint list field of the type "Note". Reading from the field is straightforward.
//Retrieving the list row
SPListItem baseItem = baseList.GetItemById(itemId) as SPListItem;
string value = Convert.ToString(baseItem["NameOfTheNoteField"]);
But then I try to write to to a Note field;
SPListItem item ...;
item["NameOfTheNoteField"] = "MyValue";
It results in the following error:
Value does not fall within the expected range ...
What does the Note field expect if not a string!?
You actually shouldn't think of it as a Note field, but a SPMultiLineText field.
To update it you first need to get the current value and edit that - also you shouldn't use Convert.ToString() with it but GetFieldValueAsHtml or GetFieldValueAsText.
Ultimately your way of setting the value should have worked. Value does not fall within the expected range could also be coming from somewhere else - e.g. you are not using the correct name of the field and hence item["NameofNoteField"] is throwing an error. Try to debug it.
Taking your example and updating the current text in the field:
SPListItem baseItem = baseList.GetItemById(itemId) as SPListItem;
SPFieldMultiLineText mlfield = baseItem.Fields.GetField("NameOfTheNoteField") as SPFieldMultiLineText;
string fieldtext = multilineField.GetFieldValueAsHtml(item["NameOfTheNoteField"], baseItem );
//or use GetFieldValueAsText
fieldtext += "I am the update of the text";
baseItem ["NameOfTheNoteField"] = fieldtext;
baseItem.Update()