How to describe (enumerate) picklist enties valid for a specific record type in Salesforce? - reflection

In apex code I want to enumerate the legal values for a picklist field. To do this I can just call Account.Foobar__c.getDescribe().getPickListValues() and I've got a list of Schema.PickListEntry values.
However it's possible to setup multiple record types for a given sObject. For example Account might have "Manufacturer", "Distributor" and "Retailer" record types. In the Salesforce setup it is possible edit (limit) the picklist entries for each field based on record type. So Retailer type accounts might only use a subset of the picklist values for the Foobar field.
So basically I want Account.Foobar__c.getDescribe().getPickListValues('Retailer') however this is not the syntax. The validFor method looks promising, but it seems like it is only for field dependent picklists - a picklist filtered only by record type returns false for isDependentPicklist.

I know this is an old post, but maybe the info below will help someone who still needs the answer.
I found here that one can actually get a list of record type specific picklist values by making a describeLayout() call.
Using your example (C#):
DescribeLayoutResult result = binding.describeLayout("Account", new string[] { "01230000000xxXxXXX" } );
PicklistEntry[] values = result.recordTypeMappings[0].picklistsForRecordType[12345].picklistValues;
Replace "01230000000xxXxXXX" with a RecordTypeId of your Retailer record type object. Use the query "SELECT Id FROM RecordType WHERE Name = 'Retailer'" to get the value.
Replace 12345 with an index of your picklist object that you would like to get values of.

You can't do it in pure Apex AFAIK, unfortunately. The metadata API does expose it.
Related opinions: http://boards.developerforce.com/t5/Apex-Code-Development/Any-way-to-obtain-picklist-values-by-record-type/td-p/287563

Related

NetSuite System Notes CASE formula returning all notes

I've added a formula(date/time) column to a saved search in NetSuite, to return a system notes' date.
My CASE formula is returning all the system notes row's, and I would like a specific row's date i.e. 'POP Host Int ID' date.
How can I specify the row to return the date from, or remove the rows with no date that are not relevant?
CASE
WHEN {systemnotes.field} = 'POP Host Int ID' AND {systemnotes.type} = 'Set'
THEN {systemnotes.date}
ELSE NULL
END
It appears that my WHEN logic works to identify the record's system notes do contain an entry for 'POP Host Int ID' but in THEN I'm not specifying which row to get the date from so it returns all rows. And I could be wrong on this part.
Example results
Example System Notes for 1 record
Thank you for your assistance.
The CASE statement doesn't determine which rows are returned, only what data is returned for that field. On the other hand, the reference to the systemnotes table creates a join that causes each record result to be repeated for every system note entry.
To avoid this, add {systemnotes.field} = 'POP Host Int ID' and {systemnotes.type} = 'Set' as Filters in the Criteria tab instead of in the WHEN conditions. You can then just add the field under results instead of needing a formula.
Edit in response to comment below:
In cases where you need one result per base record (user), but they don't all have valid values from the joined table (system notes), I'd suggest grouping the results by user, and using aggregation functions for all the columns. EG: For the column in question I'm assuming you are getting one valid result and a lot of blanks per user. If you group by user and set the Summarize function to MAX, you should just get one result where the valid value is returned. If no valid value exists from the system notes, you would still get a result from the user and that field will be blank.
If you are creating a saved search the place to do this is in the criteria section.
The views you've shared are for the System Notes pertaining to a single record.
For those views you could just use the Field selector in the Filters section to select your POP Host Ing ID field.
For a saved search you would use the Advanced view and scroll down the criteria field list. Near the bottom are the System Notes. You can filter on Field, Date etc

DimensionValuesLookup on my own EDT

I need to create an EDT that will use DimnesionValuesLookup.
So I've made an EDT with reference to my View that has DisplayValues for my specific dimension type, also I set formHelp property as DimnesionValuesLookup. And when I'm trying to open lookup on query search criteria I get an error:
Form should be called with parameters
I looked into the Init() method of DimnesionValuesLookup and found out that I need to pass DimensionAttribute as a record.
How can I do this?
Your comment did not answer my question, but I'm assuming you have a way to identify the name of the attribute for which you want to lookup values. Using the name you can select the DimensionAttribute record that you need to call the lookup form by using the findByName method of table DimensionAttribute. After that you can call the lookup form. Standard AX does something very similar in form DimensionValueInterval, take a look at the lookup method there.

Plone Catalog Search - How can I query for objects by checking for numbers in a list field type it features?

I have a dexterity content type, titled Supplier and it has a field titled supplierType and is defined in the Interface as a schema.List. The list can contain values 1, 2, or 3, which correspond to a type name. A Supplier can be more than one type (i.e. supplierType = [2,3])
Using a catalog, I want to query Suppliers whose supplierType list field contain one or more of these numbers I'm looking for.
So like I'm trying to look for a Supplier whose supplierType contains a 2 or 3.
Unfortunately, I am stuck on how a query would work. I tried doing this:
supplierTypes = [1,2]
catalog = getToolByName(getSite(),"portal_catalog")
results = catalog(portal_type='gpcl.supplier.supplier',
supplierType={"query":supplierTypes,"operator":"or"})
Edit:
Testing to see if it worked by printing results, I don't get any suppliers back, but it doesn't crash.
What would the correct approach to querying supplier objects according to the criteria that one or more numbers I am looking for are in its supplierType list?
Also, technically I could just get the list of brains and then create a list, appending objects whose supplierType field contains a one or more numbers I am looking for, but I feel a query would be more efficient.
First of all: have you created a new index in the Plone portal_catalogtool?
If not: your index type must be of KeywordIndex type (just name it supplierType). After that you simply need to query like this::
catalog(portal_type='gpcl.supplier.supplier', supplierType=[1, 3])
Refer to this: http://docs.plone.org/develop/plone/searching_and_indexing/query.html
Also: are your sure that your portal type name is "gpcl.supplier.supplier"? Try manually surf the catalog to be sure of that (from "catalog" tab in ZMI catalog tool).

Programmatically get and set field values

I have two fields I want to fill with the exactly same values; users should fill only one.
I also have a function which checks if the second field is empty. Is there any change in how the field values are obtained and set in Drupal 6, and Drupal 7?
EDIT:
I am trying to edit module right now.
Yes, I am talking about node fields.
$node array has only ID of terms I added to node. How do I get the term name, knowing its ID?
Since you tagged this question with cck, I'm going to assume you are working with node fields.
To copy the value of one field (x) to another (y), you can either install the Computed Field module and set it up so that the value of y is computed from the value of x, or you can create a custom module with something similar to the following hooks:
This hook copies all of the data from field x to field y:
function mymodule_node_presave($node) {
$node->field_y = $node->field_x;
}
This hook only copies the value of the first instance of field x to field y:
function mymodule_node_presave($node) {
$node->field_y[$node->language][0]['value'] = $node->field_x[$node->language][0]['value'];
}
You might want to do a print_r on $node->field_x and $node->field_y as the structure of your data may be different based on the type of field you are using. If you want to check if either of the fields are empty, you can wrap the assignment statement in a conditional that calls your custom function.
One good way for finding out a field's value, is using field_get_items() which is provided by field API.
field_get_items($entity_type, $entity, $field_name, $langcode = NULL);
Where:
$entity_type: Is something like 'node' or 'user',
$entity: Is the entity which it's field value is needed,
$field_name: machine name of the field,
$langcode: The language that entity is stored in, It is optional and if not provided, field_get_items will find it out automatically.

Asp.Net Sql Auto-Increment for Wall Post

I have a table that contains three columns.
"UserId" type-nvarchar
"PostAuthorId" type-nvarchar
"Post" type-text
This table will contain "wall" posts like in facebook for each user's page. I am going to use a gridview on each user's page to display the posts. The issue is I want to display them with the latest(most current) post being first and the earliest post being last.
I have never used autoincrement before and I am not sure if that is the answer. If it is, I do not know how to use it. I thought about adding a date posted column and then ordering by date.
If I end up using the date column, I could also display the date on the post. Is there a way to convert the date to a readable format?
What is the best way of implementing this type of ordering?
If you use AutoIcrement the first record will start with 1 and each record will increment from there. (default setting)
If you want to sort them by newest first do an ORDER BY ID DESC
I would suggest making a column called wallPostID then setting that to AutoIncrement and also your Primary Key
Date Formating:
If you are displaying this data in a gridView
Go to Edit Columns on your grid view
CLick on the Date field under "Selected Fields" on the bottom left
Under "BoundField properties" on the right Go to Data -> DataFormatString
{0:d} will display as 1/1/2010
This site has more info in string formatting
http://msdn.microsoft.com/en-us/library/fht0f5be.aspx
A datetime column would definitely work for something like this. Assuming you are using MS-SQL, you can also attach a default value to the column using a built-in function like GETDATE(). That way, you only have to input the data that matters and the database will take care of adding the datetime column.
For converting a datetime to a readable format try:
DateTime postDate;
string value = postDate.ToShortDateString();
You should always use an ID field that auto increments. Can also be used as your PK
I would suggest the DateTime field rather than the autoincrement simply because it will not only serve as an effective Sort field, it also preserves information that you may well want to display. If you want the most recent first you'll sort using the Date and a "DESC" modifier:
Select ... Order By [Date] DESC;
When you retrieve the data, you can retrieve it as a DateTime and modify it using C#. You can use "ToShortDateString()" as suggested by mdresser if you just wish to show the date or ToString("...") if you wish to show the time as well. You can also use SQL to convert it into a string before retrieving it:
convert(Varchar(10), #mydatetime, 101)
If you look in MSDN you'll see the various conversion codes (101 is the code used above) that can be used to translate the date in various ways.
UPDATE: You may want to use an autoincrementing field for your application for reasons other than your expressed need to sort wall entries. They are easy to use - just mark the field as an Identity if using SQL Server (other DBs are similar). As far as using them in your program, just think of the field as an Int field that you never have to set.
Now, why would you use a auto-incrementing field? Perhaps the most straightforward reason is so that they give you have an easy way to identify each record. For example, if you permit people to alter or delete their wall entries, the auto-incrementing field is ideal as it gives you a way to easily look up each record (each record will be assigned its own, unique value). You might put an "x" next to the record like StackOverflow does and make it a call back with the UID (auto-increment) value. Note that you should set up your primary key on the UID field if you'll be doing this.
Now, if you find them useful for this reason then you could also sort by the UID. I would still store the date so that you can provide Date and Time feedback as to when an entry was made on the wall but this would no longer be your indexed or sorted field.

Resources