Using Drupal 7 Computed Field to provide Date Field Token - drupal-7

In Drupal 7, I have an Event content type. When saved, I want it's URL to be /calendar/day/{yyyy-mm-dd}/{title}, where {yyyy-mm-dd} is based on field_event_date. The Token module can do this for create & change date fields, but not for a custom field I created, called field_event_date. So, to compensate, I want to create a computed field called field_event_date_Ymd, which stores the yyyy-mm-dd format from field_event_date, so that I can reference it in the URL pattern.
I'm not a PHP programmer, so can someone help me with the code for this? Is it something like this?
$entity_field[0]['value'] = $field_event_date->format('Y-m-d');

$entity_field[0]['value'] = $field_event_date->format('Y-m-d');

Related

How to create custom time field in salesforce custom object?

want to create a time custom time field .. how it is possible ?
Advance thanks
I suggest you look through Creating Custom Objects and Fields. It should help you with current question and future ones.
It is very simple. If you have already created a custom object in its detail page you can add custom fields.
And if you want your date field to be populated automatically, just create it as a formula field and use already predefined function DATE.

How to manually set a dynamic default field value in Django forms?

I am trying to create a form where the default date field value should be changed from time to time.
I have created a model with the two field values. I intend to change these fields from time to time for thousand of pages. If i can do this in the admin panel once for all the pages then i get a little stress off.
{default_start_date and default_end_date}
i would like to have these fields called as the page loads to be the default values for two other fields
{start_date and end_date}
My question i dont know how i can do this? Django or Java Script? or Both?
You could do this using a django model and its corresponding admin interface:
class DateRange(models.Model):
start_date = models.DateField()
end_date = models.DateField()
admin.site.register(Author)
This would let you adjust the DateField in the admin. It also lets you call the current value of DateRange.objects.all()[0].start_date wherever you need that in your app/templates.

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.

How to render Drupal 7 Date Field

How can I properly render exclusively end date from the Drupal 7 Date field in template file?
$node->field_start_date[LANGUAGE_NONE][0]` (is it correct?)
I can get to raw values but I want it to get formatted etc.
You can use the code below:
drupal_render(field_view_field('node', $node, 'field_end_datetime'));
field_view_field: https://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_field/7

How to hide a field in node display if it's value is 0. Drupal 7.

I am using a drupal installation as a REST server for an Android application. I store data in nodes and occasionally a field is blank, for example a location that has no phone number. I had to standardize the JSON coming out of the drupal REST server to a specified class, so I was forced to add 0, as the value in the field.. Works great in Andriod, but when viewed on the drupal site, it looks bad..
So question is, if the value of the field is 0, Id like to change it to
'None'.
I could do this in D6 with cck, but i dont know d7 field api. Thanks
You can do this in the node.tpl.php file, in the field.tpl.php file or with the template_preprocess_field function (recommended) and with so many other options with an if statement.
See an example for first template and one for second option with the preprocess function.
If you don't want to edit tpl.php files or you don't have access to the template.php file of your theme you can use the Field formatter conditions module that allows you to do this condition. Alternatives are Custom Formatters and field_formatter_css_class.

Resources