How to solve Sitecore Glass Mapper duplicate field names - sitecore

I've a template with sections below:
Section A
Title
Name
Section B
Title
Name
Looks good on Sitecore. However when TDS Glass mapper generates the code, it generates Title and name twice.
Wondering if it's possible to add the section name before each field when glass mapper generates the code.
If you ask me why, it's to avoid 248 character length error for windows file system for TDS items as I had done this as work around.
Section A
Section A Title
Section A Name
Section B
Section B Title
Section B Name
Any help will be awesome.
Thanks.

It is generally not good practice to have Fields with the same name defined multiple times in the same template. Although Sitecore will allow you to do that and will be able to identify the fields separately by the Field ID - Most code uses field names or generated code to do that. When referencing the fields by name, it will fail.
You have 2 options.
Option 1
It is better practice to either prefix the names or come up with a unique naming convention, as you have done in your example
Option 2
As an alternative you could modify the T4 template to prefix the field names when generating the code, with the section name. This would allow the code to compile. But depending on how the fields are being mapped by Glass (normally this is by field name, not ID) - it will still cause issues as Sitecore will not know which field to use.
I would go with Option 1

Related

Custom index name in South/Django

Is there a way to set our own index name in Django models? Currently, the migration scripts would create a name in format [table_name]_9fcb4ba3 and I'd like to have the name more descriptive, i.e. [table_name]_[column_name] or so.
On the Django's Model Field Reference page, it doesn't seem to have such option (https://docs.djangoproject.com/en/1.8/ref/models/fields/#db-index)
For anyone finding its way from Google - seems Django 1.11 allows you now to have a custom name for indexes. Following the documentation as described here:
Index.name
The name of the index. If name isn’t provided Django will auto-generate a name. For compatibility with different databases, index names cannot be longer than 30 characters and shouldn’t start with a number (0-9) or underscore (_).
There is no way of customizing the name for indexes as these are generated by hashing (the index name calculation uses some hashing techniques)

Storing CiviCRM extension specific configuration in database

I'm building a CiviCRM extension, which would also have an admin section with UI for setting various configuration specific to the extension. I'm looking for a recommended approach for storing the configuration in the database.
One way is to create a new table in the database specifically for this purpose, but this seems like an overkill if there are only a couple of options to be saved.
Another way could be to use the civicrm_setting table, which kind of makes sense at first, but I'm not sure if this table is meant to be used for this purpose.
Any advice would be appreciated.
Yes, you can and should definitively use civicrm_setting.
civicrm_setting has a column group_name that should contain a unique identifier for your extension. I usually put the full name of the extension, like org.example.extension but it could be any string, and in core they use label name (e.g., Preference settings).
To interact with those settings, you can do the following :
// save the setting
CRM_Core_BAO_Setting::setItem($value, 'My group name', 'my_setting_name');
// get the setting
$setting = CRM_Core_BAO_Setting::getItem('My group name', 'my_setting_name');
// get all the setting for you extension
$settings = CRM_Core_BAO_Setting::getItem('My group name');
There seems to be an API for Setting but it doesn't seem to work well in CiviCRM 4.4.x. Don't know if it is better in CiviCRM 4.5.
What you could also do (our current practice) is store your configuration logic in a special class using the singleton pattern (as CiviCRM does itslef). If you want to see an example check this:
https://github.com/CiviCooP/no.maf.oppgavexml/blob/master/CRM/Oppgavexml/Config.php

How to get the full name of a Sitecore DMS rule?

I'm using Sitecore. I want to get the full name/description of a DMS rule in programcode by Sitecore ID, for example: "Where the DayOfWeek has a value that is equal to Tuesday".
Who knows how to do this?
Thanks a lot.
Jordy
I don't know of a simple way, but the class responsible for rendering the rule text is Sitecore.Shell.Applications.Rules.RulesRenderer in Sitecore.Client.dll.
Its constructor accepts the XML from a rules field and you call the Render method, passing in a prepared HtmlTexteWriter. It also has a bunch of fairly self-explanatory private methods like RenderRule, RenderCondition etc.
I'm sure if you decompile that class you can pick out the bits you need.

Getting error while reading salesforce custom field type Rich Textarea

I am using salesforce.cfc (downloded from Riaforge) to integrate coldfusion with salesforce.
<cfset latestProductList = salesforce.queryObject("SELECT Id, Name, Description__c, Price__c, ProductImage__c FROM Product__c") />
I have created one custom object named "Product__c". This object have one custom field "ProductImage__c" type "Rich TextArea". When i an trying to get product without this custom field it is run, but when i am trying to get product with this field i am getting below error:
"INVALID_FIELD: Name, Description__c, Price__c, ProductImage__c FROM Product__c ^ ERROR at Row:1:Column:44 No such column 'ProductImage__c' on entity 'Product__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. "
But i have this field. attached screen image of salesforce below.
Thanks,
Arun
A quick look at Salesforce CFC shows that it hasn't been updated in a while. The file SalesForce.cfc is pointing at:
https://www.salesforce.com/services/Soap/u/11.1
That's version 11.1 of the API, which is quite old and is long before rich text fields came into existence.
You might be able to fix this issue by simply updating the reference in SalesForce.cfc to the latest version of the API by changing
https://www.salesforce.com/services/Soap/u/11.1
to
https://www.salesforce.com/services/Soap/u/28.0
in that file, although there's a pretty good likelihood that that will break something else, since version 28.0 will have lots of new stuff that SalesForce.cfc is not coded to handle.
In any case, your problem is in fact the API version that you're using. In cases like this, when a field type did not exist as of a certain API version, then that field is invisible for that version. In your case, your rich text field is invisible for your API version, 11.1.

Is there a way to retrieve a Sitecore item using a different language than the current context?

I have a Sitecore layout that generates a vCard from a Sitecore item, including a person's name, business address, etc, and saves it as a file on the web server for later (fast) retrieval. Part of the vCard is the organization (business) name. We're an international firm, which means that across the different locales our firm name is slightly different.
For example, in English our name is [Firm Name] LLP, while in Swedish it is [Firm Name] Advokat AB.
The language context used when generating vCards is English, but the org name is localized within Sitecore. Is it possible to switch from English to another language context to grab the localized org name, and then switch back?
Alternative Approach
The alternative I'm pondering would be to just hard-code the org name in the code, and based on the person's office address output the correct org name. The downside of this would be that I wouldn't be taking advantage of Sitecore's localization capabilities. In addition, there may be other components of the vCard that will eventually be localized - I don't want to hard-code everything.
Is this to any help?
Language theLanguage = Sitecore.Globalization.Language.Parse("sv-SE");
Item theOriginalItem = Sitecore.Context.Database.GetItem("/sitecore/content/home/theitem");
Item theLanguageSpecificItem = Sitecore.Context.Database.GetItem(theOriginalItem.ID, theLanguage);