Enterprise Architect document creation - filter - templates

Enterprise Architect was introduced to me only today, and i also got a task related to document generation, which should be done as soon as possible.
I have to write a template for doc generation, and this template should do some filtering or conditioning on a specific element.
From a closer look: I have an element, which has a special field {Element.SpecialField}, that can hold values of true or fase. If the field's value is true, then the field's name should be generated into the doc, else nothing.
Which is the easiest way to do this? Scripting or selector/fragment filters? Thanks.
EDIT:
The generated document should look something like this:
![EA Document]: http://s29.postimg.org/68edfthdz/EA_doc.jpg
The cells containing question marks are the specific element values I mentioned above the EDIT section.
There are three element fields: TagValue_X, TagValue_Y and TagValue_Z.
They can be true or "" (empty string) individually.
But in the table cell I don't want to see their values, but the names of the fields separated by commas. For example: if
{Element.valueOf(X)} == true AND {Element.valueOf(Y)} == "" AND {Element.valueOf(Z)} == true
, then the cell should contain "X, , Z".
EDIT 2: To Geert's answer.
The following script works well, when I want to to search in the Model (CTRL+ALT+A in EA 12):
SELECT t_objectproperties.Property FROM t_object, t_objectproperties
WHERE t_objectproperties.Value='True'
AND t_objectproperties.Property='X'
AND t_object.Object_ID = t_objectproperties.Object_ID
How should I modify this to apply it as a Custom Query in the fragment template? I tried some queries like this, but they never returned anything. Probably this is a basic conceptual misunderstanding issue from me...
SELECT t_objectproperties.Property AS SomeQuery
FROM t_objectproperties
WHERE t_objectproperties.Value='True'
AND t_objectproperties.Property='X'
AND t_objectproperties.Object_ID = #OBJECTID#
TemplateMain:
package>
element>
{Template - TemplateFragment}
<element
<package
TemplateFragment:
custom>
{SomeQuery}
<custom
I suppose the fragment template should be inserted into the element section.

The easiest solution would be to create an SQL fragment.
Using SQL you can return exactly the fields you need based on the PackageID passed to the template fragment.
Check the learning center (Alt-F1) for a step-by-step guide on creating SQL fragments.

Related

Treelist datasource query - Field must contain 'X'

So I am pretty new to Sitecore, and I seem to have gotten myself into an issue that I cant solve or google ;)
So I have an item, this Item has a treelist, and that treelist has a datasource "Products". Now this works fine, the issue is that I only want the items (products) displayed in my treelist, where the Product Category is "Shoes".
The Product template has a Multilist named "Categories", so i would like a query, that evaluated if one of the Categories is "Shoes" if so, include the Product in my Treelist, if not exclude it.
Can it be done with a query or do I need to do some actual code to get that result?
Any help would be much appriciated.
You can use Sitecore's fast query in source field of template field as below:
Using contains:
fast:/sitecore/content/Home/Products//*[contains(#Categories = 'IdOfShoesItem')]
Using like:
fast:/sitecore/content/Home/Products//*[#Categories = '%IdOfShoesItem%']
On older sitecore version fast query does not work, in those cases replace "fast" with "query" like below:
query:/sitecore/content/Home/Products//*[#Categories = '%IdOfShoesItem%']

how to match a field name with another field name

I have two fields that run throughout a website that I would like to match so that when a user inputs a value either of the fields, it will match the other field. I'm using Sitecore Rocks and am trying to use a query to do this.
select ##h1#, ##Title#
from /sitecore/Content/Home//*[##h1# !="##Title#"];
update set ##h1# = ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
What am I missing here?
This article talks about tapping in to the item:saving event which allows you to compare the fields values of the item before and after the changes:
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Intercepting-Item-Updates-with-Sitecore.aspx
Using this, you can determine which field has been amended, then change the other to match.
I've had to do something similar to this when a new field was added, and we wanted to set the initial value equal to an existing field. It may be a bug in Sitecore Rocks, but I found it would only update a field when a static value was part of the query.
When I ran ##h1# = ##Title#, the query analyzer would return the correct number of items updated, but no values were actually updated. However, ##h1# = '<id>' worked perfectly. After trying a number of things, I found this did what I wanted.
update set ##h1# = '' + ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
I hope that helps.

Sitecore 7 ContentSearch API with numeric POCO properties in the filter / where condition not working

I have been spending few hours on this issue now, but no luck so far. So reaching out to the community for help.
I have a data template called Product with a field called ProPrice, and some content based on this template I have enabled all fields to be indexed using the configuration <indexAllFields>true</indexAllFields>. When I rebuild the index, I see the index field (proprice) along with the terms stored in Lucene correctly (verified using Luke).
Now I use Sitecore 7 ContentSearch API to fetch content from Lucene index. And for this, I have created a POCO entity called Product, which inherits from SearchResultItem, and have also added a property for price as below:
[IndexField("proprice")]
public double Price { get; set; }
However the following LINQ query does not return any data:
var products = context.GetQueryable<Product>().Where(p => p.Price == 4.0).ToList();
When I look at Sitecore search log, the Lucene query that this translated to was - proprice:[4 TO 4]. And if I execute this query directly against the index in Luke, it returns data. I tried this with other conditions such as p.Price >= 1.0, but none worked. What is interesting is - when I remove the condition and get all records, the Price property in the Product entity is populated with the correct double value (4.0).
But if I change the query slightly as follows, it returns correct data:
var products = context.GetQueryable<Product>().Where(p => p["proprice"] == "4").ToList();
So it looks like when the condition is against numeric values, it does not work. And unfortunately, I need to filter based on a numeric range, and hence the above approach will not work for me. I can avoid ContentSearch API and directly execute the Lucene query using the Lucene provider, but I will not be able to switch to a different search provider, such as Solr, in future. Or alternatively, I can get all data, and then filter in my code - I wouldn't prefer that though.
I would appreciate any help in resolving this.
PS: Few other points:
1) I tried the field type of "ProPrice" in the data template as single line text, integer, double - none worked
2) Am using the default Lucene analyzer - Lucene.Net.Analysis.Standard.StandardAnalyzer
You need to map your index field type to system.double as follows (Notice type="System.Double"):
<field fieldName="proprice" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.Double" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="[YOUR ANALYZER]" />
</field>
I think you need the type converter attribute adding to the field. I've done this in my projects and filtering on numbers has worked fine:
So change the property to:
[IndexField("proprice")]
[TypeConverter(typeof(IndexFieldNumberValueConverter))]
public double Price { get; set; }
And you should be able to filter.

Sitecore Fast Query select attribute values

Is there a way by using XPath Builder under Developer Center inside Sitecore Shell (a Fast Query interface) to select a particular attribute from an item. Example:
/sitecore/content/Home/Products/*[##templatename = 'Product Group']/#id
I would expect to see a collection of id's to be returned where id is an attribute of an item. If yes is it possible to extract an attribute with a space bar? Example:
/sitecore/content/Home/Products/*[##templatename = 'Product Group']/#more info
EDIT
The thing that I want to achieve is to get a collection of items (I have few hounded items here), not one particular item. That's why I am not interested in adding additional conditions, like specific item id or title. I want to see a collection of values of a specific attribute. As in example showed above, I want to see a collection of values that are assign to 'more info' attribute. Once again I am expecting to see few hounded different values that are set to 'more info' attribute.
EDIT2
There is a problem with a production, a critical stuff. There is no access to it other then thru Sitecore shell, but I don't have permissions to add/install additional packages. I know how to get this info by implementing custom code, or queering db directly, but I simply do not have permission to do it. Guys that will be able to grant me need credentials will wake up in 6 hours, so I was hoping to do whatever I can to analyse the situation. I would accept Maras answer if it was an answer not a comment - there is no way I can do it using fast query. thanks for help.
Try using #
/sitecore/content/Home/Products/*[##templatename = 'Product Group']/##more info#
This is the way around when selecting items with fields that contain spaces. Having said that I don't know if you would be able to get a specific result or not for your specific question but give it a try.
For example, consider this query which returns Product S1
fast:/sitecore/content/home/*[#Title = 'Item 1' and ##templatename = 'Product Group1']//*[#Title = 'Product S1' and ##id = '{787EE6C5-0885-495D-855E-1D129C643E55}']
However, if you place the special attribute (i.e. ##id) at the beginning of the condition, the query will not return a result.
fast:/sitecore/content/home/*[##templatename = 'Product Group1' and #Title = 'Product S1']//*[##id = '{787EE6C5-0885-495D-855E-1D129C643E55}' and #Title = 'Product S1']
Remember this, Sitecore Fast Query only supports the following special attributes:
##id
##name
##key
##templateid
##templatename
##templatekey
##masterid
##parentid
Let us know if this helps.

Counting database entries by field type in django

I have a model in my django project called "change" and it has a field called "change_type". There are multiple values within the change_type field to include "move", "new", "edit" and others with new types being added randomly over any given period of time. I am currently using normal django queries to select groups of entries within the change model.
Is there a quick method to determine what unique entries are in the change_type field? Is there a quick method to return a count of each entry type?
After finding the solution, it is really simple.
Change.objects.all().values('change_type').distinct()
Putting it together:
occurrences = {}
change_types = Change.objects.values_list('change_type', flat=True).distinct()
for type in change_types:
occurrences[type] = Change.objects.filter(change_type=type).count()
http://docs.djangoproject.com/en/dev/topics/db/managers/ maybe that will be helpful for You.
This can now be much more effectively implemented using aggregation:
Change.objects.values('change_type').annotate(Count('change_‌​type'))
The output contain change_type__count field for each respective change_type.

Categories