SharePoint 2010: Error Mapping to Picture Hyperlink with SPMetal - sharepoint-2010

Whenever I have a column of type hyperlink with the format set for pictures, I get an error whenever there is actually a value in that column.
The exception it throws is "Specified cast is not valid".
My thought is that the problem is either here (the FieldType being set to Url):
[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "FOO", Storage = "FOO_", FieldType = "Url")]
public string FOO
{
get
{
return this._FOO;
}
set
{
if ((value != this._FOO))
{
this.OnPropertyChanging("FOO", this._FOO);
this._FOO = value;
this.OnPropertyChanged("FOO");
}
}
}
Or here (it being cast to a string):
private string _FOO;
But I'd have no idea what the proper values for either of those fields should be.
Any help would be greatly appreciated.
It works whenever this field does not have data in it and I JUST used SPMetal to generate the class, so I'll get the two most obvious questions out of the way.

Link to the answer:
https://mgreasly.wordpress.com/2012/06/25/spmetal-and-workflow-associations/
Turns out it is a known bug when mapping lists that have associated workflows.
SPMetal assigns it as a nullable integer when it's supposed to be an Object, hence the cast error.
Workaround: manually edit the mappings to make the type it returns an object or ignore the column by using a parameter map.

Related

(Problem solved) Set the value of a livedata variable of type <data class> to a list of strings?

How to populate the value of this variable:
private val _urlList = MutableLiveData<List<Url>>()
of type Url:
data class Url(
val imgSrcUrl: String
)
with the incoming list of url strings from a firebase call?
Here is where the magic happens:
private fun getData(){
viewModelScope.launch {
try {
getImagesUrl {
"Here where I need to set the value of the variable to a listOf(it) with it being strings
of urls retrieved from firebase storage"
}
}catch (e: Exception){
"Handling the error"
}
}
}
Edit
The map function #dominicoder provided solved my problem, answer accepted.
Thank you all for your help
Your question is unclear because you're showing a live data of a single Url object but asking to stuff it with a list of strings. So first, your live data object needs to change to a list of Urls:
private val _urlList = MutableLiveData<List<Url>>()
Then, assuming getImagesUrl yields a list of strings, if I understood you correctly, then you would map that to a list of Urls:
getImagesUrl { listOfImageUrlStrings ->
_urlList.value = listOfImageUrlStrings.map { imageUrlString -> Url(imageUrlString) }
}
If that does not answer your question, you really need to review it and clarify.
You can set values on the MutableLiveDataObject in two ways (depends on what you're doing).
Setting the value as normal from the UI thread can be done with:
myLiveData.value = myobject
If you're setting it from a background thread like you might in a coroutine with a suspended function or async task etc then use:
myLiveData.postValue(myObject)
It's not clear from your question whether the LiveData is meant to hold a list as you mention both lists and single values. But your LiveData holds a set the values as a collection like a list, set or map. It's can be treated as a whole object so adding a value later needs to have the whole collection set again like:
myLiveData.value = mutableListOf<Url>()
//Response received and object created
myLiveData.value = myLiveData.value.apply {
add(myObject)
}
Or if the value is mutable updating the existing value (preferred as it's cleaner):
myLiveData.value.add(myObject)
The problem with that approach is you're exposing the map as a mutable/writeable object. Allowing accessors to change the values which you might not want.

Empty object with union type in graphQL

When I' using union type in my graphQL schema I use it typically like this:
const documentTypeDefs = gql`
union TestType = TypeExample1 | TypeExample2
type Document {
exampleKey: TestType
}
`
Then I resolve it like this:
TestType: {
__resolveType(obj) {
if(obj.property1) {
return 'TypeExample1';
}
if(obj.property2) {
return 'TypeExample2';
}
return null;
},
}
But sometimes I'm getting empty object in my resolving function (ie. obj is {}). I thought returning null or undefined will do the job but unfortunately I'm getting error:
"Abstract type ItemsType must resolve to an Object type at runtime for field Document.exampleKey with value {}, received \"{}\". Either the ItemsType type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."
How can I resolve empty object then?
Thank you!
If an empty object is being passed to __resolveType, that means your field is resolving to an empty object. That means either the value being returned inside your resolver is an empty object, or else the Promise returned is resolving to one.
If you're working with a field that returns a List, it's also possible for just one of the items being returned to be an empty object. This is particularly likely when working with MongoDB if one of the documents you're getting is actually empty or at least missing the fields you've specified in your mongoose schema.

Set Pointer to Object in Parse

I keep running into the error when trying to set a pointer to another class object in Parse. What is the correct format to set the pointer from an objectID?
Error:
[Error]: invalid type for key RestaurantName, expected *Restaurant, but got string (Code: 111, Version: 1.6.1)
Code:
var uploadPhoto = PFObject(className:"FoodPhoto")
uploadPhoto.setObject("lZJJHkFmQl", forKey: "RestaurantName")
uploadPhoto["PhotoName"] = "title"
let imageFile = PFFile(name:"image.png", data:imageData)
uploadPhoto["PhotoUploaded"] = imageFile
uploadPhoto["Votes"] = 0
uploadPhoto.saveInBackgroundWithBlock {
(success: Bool, error: NSError!) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
You can create a pointer with the
PFObject(withoutDataWithClassName: "your_class_name", objectId: "your_object_id")
function, and set that to the field.
You have an object id string and a pointer is a reference to an actual object. That object id represents, or rather uniquely identifies, the object, but you can't diectly create a pointer with it. You need to get the object associated with the id.
If you already have it, great, substitute it where you currently put the string.
If you don't, you need to get it by running a query. Technically you could pass the string object id in a different field and have cloud code query and set the pointer (which would be more efficient than querying from the device if you don't already have the object).

How to import data from sql into Word custom properties with vba

I'm evaluating ways of importing field data from a sql database into Word. Each field has small amounts of text in them for company name, legal status, address line, etc. I can pull it into a table, but I don't want the user to see it. I would really like to import the data into a set of custom properties in a template, and then use those to reference in the Word doc using codes. Does anyone have any links or examples that could help me do that?
I have no problem in doing the custom properties side of things. I am not sure how I can get the data into a custom property.
You help would be appreciated.
I haven't found a satisfactory solution to this, and I need to keep it all in VBA, given a few specific restrictions by the client.
I now know that the source is a MSSQL2008 server. I want to source company address and level details in the table, but ideally I want to pot these details into a set of custom properties in the document. I can then reference these into the document, and update the custom properties when needed.
You can do it using an add-in written in for instance C#. With VSTO, you can easily and reliably download facts from most databases and put them in custom properties. An alternative is the use of Invantive Composition, which allows you to do this by specifying it in a model of the template, see this model definition: . Please note that I work at the company that made it, so I'm biased.
If you want to go down the road with C#, use code similar to in for instance ApplicationUtility.cs of your project (code taken from Invantive Control, but put in public here for your convenience):
Getting property value
private object GetWordBuiltInProperty(_Word.Document wordDocument, _Word.WdBuiltInProperty property)
{
try
{
if (wordDocument != null)
{
return wordDocument.BuiltInDocumentProperties[property].Value;
}
}
Or changing it
private void CreateDocumentProperty(_Word.Document wordDocument, string name, MsoDocProperties type, object value)
{
Debug.Assert(wordDocument != null, "Word document cannot be null!");
Debug.Assert(!string.IsNullOrEmpty(name), "Name cannot be null!");
object property = this.GetDocumentProperty(wordDocument, name);
if (property == null)
{
Type t = wordDocument.CustomDocumentProperties.GetType();
t.InvokeMember("Add", BindingFlags.InvokeMethod, null, wordDocument.CustomDocumentProperties, new object[] { name, false, type, value });
}
}
private void CreateOrReplaceDocumentProperty(_Word.Document wordDocument, string name, MsoDocProperties type, object value)
{
Debug.Assert(wordDocument != null, "Word document cannot be null!");
Debug.Assert(!string.IsNullOrEmpty(name), "Name cannot be null!");
object property = this.GetDocumentProperty(wordDocument, name);
if (property == null)
{
//
// Add property.
//
this.CreateDocumentProperty(wordDocument, name, type, value);
}
else
{
//
// Set value.
//
this.SetDocumentPropertyValue(wordDocument, name, value);
}
}
private void SetDocumentPropertyValue(_Word.Document wordDocument, string name, object value)
{
object property = this.GetDocumentProperty(wordDocument, name);
if (property != null)
{
Type t = property.GetType();
t.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { value });
}
}

FileHelper library - custom error messages

I am use the FileHelper to parse CSV files. Error messages encountered when parsing the file are displayed to the end user. The end user may not be able to make sense of the technical error message. Not too many clerks know what an Int32 is or Class: UploadFooDto.
I would like to customize the error messages so they are more user friendly. Something like:
Line 1. Column 2. A string (a) was entered instead of a number
Line 2. Column 3. '13-14-15' is not a valid date
I cannot find anything in the API that would allow me to customize the error messages. The most I have so far are some extension methods to clean up the errors:
public static class FileHelperExceptionExtensions
{
public static string BuildMessage(this ErrorInfo error)
{
if (error.ExceptionInfo is ConvertException)
{
return ((ConvertException)error.ExceptionInfo).BuildMessage();
}
if (error.ExceptionInfo is BadUsageException)
{
var message = error.ExceptionInfo.Message;
var readTo = message.IndexOf("Class:");
return message.Substring(0, readTo);
}
return string.Format("Line: {0}. An unspecific error occured.", error.LineNumber);
}
public static string BuildMessage(this ConvertException exception)
{
return string.Format("Line: {0}. Column: {1}. Field: {2}. Cannot convert '{3}' to type: '{4}'", exception.LineNumber, exception.ColumnNumber, exception.FieldName, exception.FieldStringValue, exception.FieldType.Name);
}
}
but these extensions still leave a lot to be desired. Is it possible to customize the error messages?
It's hard to improve on your extension methods without it being more hassle than it's worth.
You cannot subclass the default converters (e.g., FileHelpers.ConvertHelpers.Int32Converter since they are internal and sealed). You could create your own custom converter for each type (and base it on the corresponding source code from FileHelpers, e.g., Int32Converter). Then you can raise an alternative to ConvertException (also sealed so you cannot subclass) which would format the message differently.