I am creating an application to display the notification like facebook. I have database schema to save the user-specific notification. The notification message contains the placeholders. E.g. Suppose we have below notification messages (Calling it Notification Template):
{FrinedName} like your photo.
{FriendName} like your page {PageName}.
{FrinedName} posted a message in {groupName}.
It's {friendName} birthday today.
{FriendName} and {#count} likes your photo
So here the text inside {} represents placeholder and the value of these placeholders need to be replaced at the runtime.
Now I want to keep these placeholders and their value source in database tables.
The Value of different placeholders may refer to the different columns in different tables. (E.g. the value of {FriendName} may belong to the User tables LoginName column, value of {PageName} will refer to Pages table's Name column and the value of {groupname} placeholder refer to the the Groups tables Name column).
So, I would like to get the data dynamically for the placeholders. What is the best way to store such type of data in the database (something like below).
dbo.NotificationTemplates - Table to store all the notification templates
dbo.TemplatePlaceholders - Table to store the placeholders in the template
dbo.TemplatePlaceholdersMapping - Table to store the mapping of placeholders in a template.
dbo.PlaceholderValueProvider - table to store the placeholder's value source, i.e. from where to get the value for placeholder.
My suggestion is to use scalar function, you can have multiple conditions in scalar function and at the end, return your result in one column
Related
I am working on a report type "Activities with Contacts" and I see that a field called "Last Activity"(date)(api_name: CONTACT_LAST_ACTIVITY) is visible and I am able to add it to the report columns.
I also see that this column is coming from contacts object.
But when I go to object manager and check this in contact's object fields and relationships, this column is not there.
Please let me know if I am missing something. Why is this field visible in report but not anywhere else?
I have checked this column in task, activities, events, accounts objects as well.
Also, this field is not visible in field sets.
Last Activity is a calculated field, it depends in a lot of conditions. It's not in the list of fields of the object. More info about the calculation: https://help.salesforce.com/s/articleView?id=000385365&type=1
If you need it as a field in the object, you can create a formula field that uses the field LastActivityDate, like the example in salesforce help for the lead object: https://help.salesforce.com/s/articleView?id=000387759&type=1
I have seen the link below which explains that it is possible to create a filter on one field between sources by generating a calculated field and then assigning the same field ID to both fields for filtering purposes:
Using the same filter control for two different data sources
But my question is whether or not it is possible to make that particular field (that is now shared between 2 data sources) dependent on other filters that are tied to 1 of the data sources?
Example would be:
One dataset with country name and city name
One dataset with city name and population
I've generated a calculated field to be able to filter on city name since they now share the same field_id.
What I'd like to do is use a control that selects country from dataset 1 and then automatically filters city_name in both datasets.
I realize I could just pull country name into my dataset in the example above, but in my real dataset there are a significant number of fields I'd be looking to be able to use for filters.
If a filter is set, all charts and filters are updated with that setting. However, it would be a huge mess, if any of these objects would automatically changes the filters again. Then all object would be updated again and the filter setting could be changed once more, thus ending up in an infinity loop.
Therefore, a filter can only apply to a field. If this should cause further filtering an user action is needed. It would be possible to write a customer vizualisation, which would mimic an user action, but again it could end in an infinity loop.
I have never used SQL. I would like to create a table with different columns. Then I would like to create a program which allows the user to insert entries. For each token of the entry, I would like to retrieve from an attribute of the corresponding column the way this particular part of the data entry should be entered. For example, I will have some data retrieved automatically (e.g. the date and time), some for which I will propose the user to insert the last added value, and some for which I will ask the user to explicitly type the value.
I do not know if "Attribute" is the right term; the attributes that I have available for each column at the moment are "Name", "DataType" and "Description"
I want that my program dynamically adapts to the table columns and to the property of each column, especially because I will have several tables to be filled. So my program would check the table columns with their properties, and interact with the user for the creation of a new entry.
Is there a possibility to add attributes to a column?
Otherwise I will have to encode the information I need for my program in the "Description" field (aka "MS_Description").
I googled terms like "sql add column attribute", but I could only find results concerning how to add a column to a table.
I've been using cakephp for a while, but have not learned all the ins and outs yet so I may be missing something simple. Or the problem may lie with my database structure. Either way, if anyone has any idea of what I'm doing wrong, please share.
Is there a way to order the data returned by cakephp's find using values stored in another table?
I am creating custom form fields on a per category basis, so when I choose a particular category to post in, custom fields will be added to my form. I have 3 tables: Posts, Fields, and Answers. The Posts table stores the basic static information for the post, such as id, category_id, title, and description. The Fields table stores the custom field data, such as category_id, field_label, field size, etc. The Answers table stores the values that are entered for particular fields, such as post_id, field_id, value.
I am trying to display the posts for a particular category, and create html table headers on the fly, using select fields, set by a column toggle in the fields table, and also select the answers associated with that particular field and post.
I am able to select all the data I want, and paginate everything just fine, but what I can't seem to figure out is how to order the data using one of the dynamic column values. For example, if I have year, make, and model as 3 custom fields, I would like to click the year column to sort my results by the year values, and if I click the make column, I would like to sort my results by the make values, etc.
I know how to order the results by a particular field inside the posts table, such as id or title, but is it possible to order using the custom fields? Am I setting up the database and/or something else wrong, and if not is there are particular cakephp method or sql command that I need to use in order to sort by the custom fields? I'm not really well versed in complex sql commands.
Thanks.
I'd suggest you pass the field name and sort direction in the URL (GET param). So when you have your table header link, form it so that it links to a URL as so:
http://somesite.com/pages/index/sort:customfield1/dir:asc
Then when you're grabbing the data from the db in your find() query, include the named parameters as the order parameter that can be sent to find.
You'll need to determine a default sorting column and direction. Maybe have that be selectable with a boolean field in the schema -- if there are no parameters sent to the action above, pull the field from your other table that has default set to true in the record.
To clarify: when a user visits a given action, first you'll pull the custom fields from the other table. Then using those fields (either the default as mentioned above, or the named params passed in the URL) form the query for the actual data, using the order parameter.
I am looking at a problem which would involve users uploading lists of records with various field structures into an application. The 2nd part of this would be to also allow the users to specify fields to capture information.
This is a step beyond anything ive done up to this point where i would have designed a static RDMS structure myself. In some respects all records will be treated the same so there will be some common fields required for each. Almost all queries will be run on these common fields.
My first thought would be to dynamically generate a new table for each import and another for each data capture field spec.Then have a master table with a guid for every record in the application along with the common fields and then fields that specify the name of the table the data was imported to and name of table with the data capture fields.
Further information (metadata?) about the fields in the dynamically generated tables could be stored in xml or in a 'property' table.
This would mean as users log into the application i would be dynamically choosing which table of data to presented to the user, and there would be a large number of tables in the database if it was say not only multiuser but then multitennant.
My question is are there other methods to solving this kind of varaible field issue, im i going down an unadvised path here?
I believe that EAV would require me to have a table defining the fields for each import / data capture spec and then another table with the import - field - values data and that seems impracticle.
I hate storing XML in the database, but this is a perfect example of when it makes sense. Store the user imports in XML initially. As your data schema matures, you can later decide which tables to persist for your larger clients. When the users pick which fields they want to query, that's when you come back and build a solid schema.
What kind is each field? Could the type of field be different for each record?
I am working on a program now that does this sorta and the way we handle it is basically a record table which points to a recordfield table. the recordfield table contains all of the fields along with the field name of the actual field in the database(the column name). We then have a recorddata table which is where all the data goes for each record. We also store a record_id telling it which record it is holding.
This is how we do it where if each column for the record is the same type, then we don't need to add new columns to the table, and if it has more fields or fields of a different type, then we add fields as appropriate to the data table.
I think this is what you are talking about.. correct me if I'm wrong.
I think that one additional table for each type of user defined field for the table that the user can add the fields to is a good way to go.
Say you load your records into user_records(id), that table would have an id column which is a foreign key in the user defined fields tables.
user defined string fields would go in user_records_string(id, name), where id is a foreign key to user_records(id), and name is a string, or a foreign key to a list of user defined string fields.
Searching on them requires joining them in to the base table, probably with a sub-select to filter down to one field based on the user meta-data, so that the right field can be added to the query.
To simulate the user creating multiple tables, you can have a foreign key in the user_records table that points at a table list, and filter on that when querying for a single table.
This would allow your schema to be static while allowing the user to arbitrarily add fields and tables.