How can I use RelationshipFilter in 2sxc Visual Query with text field instead of entity field? - dotnetnuke

I'm trying to do the same as this example does under title "Attribute-On-Relationship to Query other Fields".
I'm editing Blog application visual query.
So I have RelationshipFilter, which takes entities of type Category via Default in point. And I want to filter them by field Name. Here I can get list of names either from params or from list of posts and their categories. That's not a problem as far as I understand.
So looks like Name has to be of entity type. I'm struggling right now with this filter, since I want to filter Category by field Name of simple text type. Which means that I have nothing to specify in Relationship Attribute. EntityTitle or just empty Relationship Attribute field don't work and cause Bad Request error. So is there a way to make it work?
P.S. ValueFilter is not an option, since it doesn't support returning nothing if there are no items, that satisfy condition and also it supports only filter by item's Attribute, that contains Value and no option that Value can contain any in Attribute with separator.

The RelationshipFilter is only meant for relationships (item with item) - and you seem to want to do a string-compare.
I'm not really sure what you should do because I don't have context, but if things get really special, best use LINQ instead. Check out the tutorials for LINQ here: https://2sxc.org/dnn-tutorials/en/razor/linq/home

Related

How to create new entity (node type) using drupal rule

I have content type award with few fields (user, position, lesson).
I have create a rule to create new node in rule actions.
When i select node type in rule it's show only two fieds : title and author.
How i get all other fields in rules action or condition .
Thanks
You have to create additional actions to set data values for the additional fields you want filled in.
It looks like (part of) what you're trying to do, is to add a Rules Action like "Set a data value" for the fields you mentioned (like lesson, etc).
But before you will be able to create a Rules Action like "Set a data value" for your field(s), you have to make sure to add a Rules Condition Entity has field (related to the field for which you want to set a value). And make sure to add that Entity has field condition BEFORE other Rules Conditions in which you might want to refer to this field. Depending on what exactly you want to do in your custom rule, an alternative might be to use content is of type.
That's also what is mentioned in the Rules UI, e.g. when you're adding a "data comparison" condition: somewhere it says:
The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type').
For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in it.

How do I get the SalesForce record id in a custom field

I wanted to add a simple read-only URL-field to 'opportunities' in SalesForce that contains a link to an external webpage with the 15-char record id (used in the salesforce urls) attached to it . To do this I wen to /ui/setup/Setup?setupid=Opportunity --> fields and created a new field under 'Opportunity Custom Fields & Relationships'.
I chose a field with data type 'URL' and added a default value. I thought
"http://example.com/?sfid="&id would do the trick, but this returns
Error: Field id may not be used in this type of formula
This is a vague error. Is my syntax of a default value wrong, or am i using the 'id' parameter in a wrong way? And what is the right way to do this?
I'm new to SalesForce, as you probably already have guessed.
As the other answer stated - Id will be known only after insert meaning the "default value" trick won't work for you.
You have some other options though:
Workflow rule that would be populating the URL field after save.
Formula field of type text that uses HYPERLINK function
HYPERLINK("http://example.com/?sfid=" & Id , "See " & Name & " in ext. system")
Custom link (similar to custom buttons, they appear on the bottom of the page layout. Search them in online help)
The difference between 2 and 3 is quite minor. Custom links can appear only on the record's detail view while formula fields & other urls are well... fields - so they can be used in reports, listviews etc.
You'd have to decide which version suits you best.
This is a great question. You're right, the error is very vague.
To begin with, read some of the documentation on default fields. Pay particular attention to the order of operations:
The user chooses to create a new record.
Default field value is executed.
Salesforce displays the edit page with the default field value pre-populated.
The user enters the fields for the new record.
The user saves the new record.
Default field values are calculated before any other record data including the id are available. For this reason, they cannot be calculated based on other record fields. Especially the record id, which has not yet been assigned.
To get this functionality, you will need to create a workflow rule that fires on record creation and inserts the proper value into your field.
It would be nice if we could have formula URL fields, but we don't. EDIT: I am dumb and forgot about using HYPERLINK in text formula fields, as eyescream correctly points out.

Field Collections of Entity References in Views

I have been tinkering with this problem and trying to research for a few hours. I am still getting familiar with the entity API for Drupal 7, and have been trying to work with PHP but to no avail--I think I am missing something VERY obvious as a result of my tired brain over-thinking things.
I have two Content Types, CT1 and CT2. CT1 has a field that can hold multiple Field Collection values. In this Field Collection (field_coll_ct2) one of the fields (field_ct2_ref) is an Entity Reference to a node of content type CT2.
Now, when I am looking at a single node of type CT1, I want a block View that will show me all of the CT2 nodes referenced in that CT1 node's field_coll_ct2 field collection field.
My primary approach, which has worked on non-field collection fields of the same kind of relation, is to add a contextual filter to the view on Content:NID. From there, since it is a block and URL parameter passing is out of the question (there are so many of these kinds of relations between 7-8 different content types, at different tuples per node, it is absolutely not feasible to use the URL for parameter-passing) I have it set to 'Provide default value' of type 'PHP' and 'allow multiple values' and here is where it gets hairy.
I need to get all of the field_ct2_ref entity references in the currently-viewed node's field_coll_ct2 field collections. I've tried using:
$wrapper = entity_metadata_wrapper($entity_type, $entity);
return $wrapper->field_coll_ct2->field_ct2_ref->value();
or
$node=menu_get_object();
foreach ($node->field_coll_ct2['und'] as $record)
{
$values[]= $record['value'];
}
foreach($values as $val){
$tgts[]=$val['every'][index]['possible'];
}
return $tgts[omg];
and probably close to a hundred variations of the above trying to get it to return something that vaguely resembled an entity reference to a CT2 type node.
I can't seem to dig deeply enough into the entity/field references to get to the field_ct2_ref['und'][0]['target_id'] that has worked for all non-field collection fields with this kind of relationship. Or I get AJAX errors telling me 'Unknown data property field_coll_ct2' or console errors saying that every index I try to throw at these array objects (to even just get ONE of the values) is wrong.
Is there an easier way of doing this? Am I missing something simple and obvious--either in the way I'm implementing my View or the PHP itself?
For what it's worth, I've been able to narrow down the view results without any contextual filter by selecting a relation to 'Referencing Entity: field_ct2_ref' but it shows ALL CT2 nodes referenced by ANY CT1 type node rather than the specific CT1 type node I'm looking at.
Thank you!

Drupal 7 views filter by node's taxonomy term

I have a similar question to my previous one (Drupal 7 views filter by dynamic taxonomy term), it's only the other way round.
I have a "partner" content type, each with it's own taxonomy term. The other content type is a regular page with multiple terms from the "partner" vocabulary. In my regular nodes, I want to include a few of the "partners" in a view block.
The view should filter only those relevant partner nodes (those tagged with one of the regular node's tags).
Could it be done this way? The problem is that I can't get the term names from URL via contextual filters...
After googling the whole afternoon (and posting it there), I eventually found the answer.
It's based on a tutorial on scito.ch (thanks), with only a few modifications. On the Content: Has taxonomy term ID (with depth) filter, be sure to check the Allow multiple values checkbox. Also (there's a lot of wrong tuts for that), don't specify anything in the WHEN THE FILTER VALUE IS AVAILABLE OR A DEFAULT IS PROVIDED. It's important you specify all those 3 contextual filters.
Hope this helps someone and saves him a sunny afternoon :)

Write-once fields in Django models

I'm having a pretty hard time trying to create a write-once field in a Django model. Ideally I'd want it to work like a final variable, although I can settle for simply preventing it from being edited through the admin.
I know there is a solution for read-only fields, but it also affects the add form, and I don't want the field to be read-only there.
Use get_readonly_fields(), and return a tuple with the write-once field name if obj exists, or an empty tuple if obj is None.
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields

Resources