I'm trying to use CMSImport to map data to an XPath CheckBoxList from uComponents but cannot for the life of me figure out how to get the values of the existing CheckBoxes. I've tried pulling them out as PreValues but the only result I can get from that is: {"XPath":"//Color","UseXml":true,"UseIds":true} which is the path definition of the CheckboxList, but not the values. Any thoughts on how to use this path definition to pull the actual checkbox values? The code I'm using is below. Thanks,
SortedList preValues = PreValues.GetPreValues(dataTypeDefinitionID);
foreach (DictionaryEntry entry in preValues)
{
PreValue prevalue = entry.Value as PreValue;
throw new System.ArgumentException(prevalue.Value.ToString(), "");
}
The available nodes based on your XPath aren't stored anywhere within the datatype, they are searched for at runtime when you open a page with your datatype.
If you check out the source code, you can see it's using uQuery.GetNodesByXPath(this.options.XPath).ToNameIds();
uQuery is part of uComponents - so best recommendation might be to reference the uComponents DLL in your project here and use the same method they are using.
When you say that you are using CMSImport to map the data... where are you getting the data from?
From looking at your config of the XPathCheckBoxList, you are using XML and storing the NodeIds; which means that you would need to get your data into a suitable format (building it up as a string), so that it is ready for importing... e.g.
Great to see the answers of all. By default this datatype isn't supported by CMSImport. What you need to do is deliver the information in a format so the XPathCheckboxList understands it. this can either be the complete xml as Lee described. CMSImport handles this different for the Datatypes that are supported. The API comes with a FieldAdapter that basically inspects the documentproperty where it's mapped against and thansform the incoming data to the recuired format. So in this case you could write your own FieldAdapter that takes a comma seperated list of node id's and convert that to the xml format Lee mentioned.
Below an example that I use myself for the tags datatype. You see that the FieldAdapter derives from the IFieldAdapter interface. Then it will be picked up in the Import process.The DataTypeId property is the GUID that you see when you open the dataype in Umbraco. This needs to corresponent with the DataTypeId for the XpathCheckBoxList in your case. Then it will be picked up automatically and you can implement the transformation in the Parse method
///<summary>/// Field Adapter for the default Tags Datatype///</summary>publicclassTagsFieldAdapter :IFieldAdapter
{
publicGuid DataTypeId
{
get { returnnewGuid("4023e540-92f5-11dd-ad8b-0800200c9a66"); }
}
///<summary>/// Use the TagHelper to parse and store the data///</summary>publicobject Parse(object value, umbraco.cms.businesslogic.property.Property property, FieldAdapterOptions fieldAdapterOptions)
{
string tagGroup = string.Format("{0}", property.GetPreValue());
returnTagHelper.ParseTagValues(value, property,tagGroup);
}
}
Import to uComponents XPath CheckBoxList
I'm trying to use CMSImport to map data to an XPath CheckBoxList from uComponents but cannot for the life of me figure out how to get the values of the existing CheckBoxes. I've tried pulling them out as PreValues but the only result I can get from that is: {"XPath":"//Color","UseXml":true,"UseIds":true} which is the path definition of the CheckboxList, but not the values. Any thoughts on how to use this path definition to pull the actual checkbox values? The code I'm using is below. Thanks,
Hi Tony,
The available nodes based on your XPath aren't stored anywhere within the datatype, they are searched for at runtime when you open a page with your datatype.
If you check out the source code, you can see it's using uQuery.GetNodesByXPath(this.options.XPath).ToNameIds();
uQuery is part of uComponents - so best recommendation might be to reference the uComponents DLL in your project here and use the same method they are using.
HTH,
Tom
Hi Tony,
When you say that you are using CMSImport to map the data... where are you getting the data from?
From looking at your config of the XPathCheckBoxList, you are using XML and storing the NodeIds; which means that you would need to get your data into a suitable format (building it up as a string), so that it is ready for importing... e.g.
As Tom says, the JSON string from the data-type's config isn't used against the values.
Cheers, Lee.
Hi Tony,
Great to see the answers of all. By default this datatype isn't supported by CMSImport. What you need to do is deliver the information in a format so the XPathCheckboxList understands it. this can either be the complete xml as Lee described. CMSImport handles this different for the Datatypes that are supported. The API comes with a FieldAdapter that basically inspects the documentproperty where it's mapped against and thansform the incoming data to the recuired format. So in this case you could write your own FieldAdapter that takes a comma seperated list of node id's and convert that to the xml format Lee mentioned.
Below an example that I use myself for the tags datatype. You see that the FieldAdapter derives from the IFieldAdapter interface. Then it will be picked up in the Import process.The DataTypeId property is the GUID that you see when you open the dataype in Umbraco. This needs to corresponent with the DataTypeId for the XpathCheckBoxList in your case. Then it will be picked up automatically and you can implement the transformation in the Parse method
FieldAdapters are also documented in the CMSImport manual. http://cmsimport.com/media/2940/cmsimport%20manual.pdf
Cheers,
Richard
is working on a reply...