New field types in Gentics Mesh schema - graph-databases

I'd like to add custom field types like 'email' or other strings that could use regex validation.
Also, numeric fields with validation like < or > or formatting like money.
I was thinking about storing a mapping of schema uuid + field name + field type, and have the UI query a new rest api to get the validation and formatting criteria when editing a node?
Does that sound like a good approach? or is there a better one?
I'm new to mesh, so I'm still learning how to approach customizations.
Thanks!

I think this relates to issue 112. At the moment it is not possible to add custom validation or custom field types. In the future more specific constraints can be added. Additionally we also plan to add a "control" property to schema fields. This field can be used to store any JSON. This JSON control property value can in turn be used in the UI to add custom form behavior or control how front-ends display/handle the value.

Related

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

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

How can I modify the meta data of any field using apex

I am trying to change the metadata of fields of a object in salesforce using Apex. For example I am trying to make all required field non-required. I was able to retrieve all the required fields using the schema class and using methods like isNillable(). I wanted to ask if there is any way I can modify the metadata.
I have searched a lot regarding this but could not find any helpful results.
Schema.DescribeSObjectResult a_desc = objects.get(Name_of_of_object_whose_fields_are_to_be_retrieved).getDescribe();
Map<String, Schema.SObjectField> a_fields = a_desc.fields.getMap();
Set<string> x=a_fields.keySet();
//I am making a map of fieldname and bool(field required or not)
Map<String,boolean> result=new Map<String,boolean>();
for(String p:x)
result.put(p,a_fields.get(p).getDescribe().isCreateable() && !a_fields.get(p).getDescribe().isNillable() && !a_fields.get(p).getDescribe().isDefaultedOnCreate());
//what I want is to modify isNillable and other attributes and make these changes to the fields.
You can't make all required fields non-required because many of them are required at the database level and cannot be modified.
For example, the Name field (on any object that has a Name field) is always required. You cannot change this property. Likewise, Master-Detail relationship fields are always required, on standard and child objects.
To change the metadata of custom fields that are modifiable, you would have to use the Metadata API. It's not available in Apex, unless you use a wrapper like apex-mdapi. As a warning, modifying your org's metadata in a broad-based way via Apex is dangerous. You can cause damage to your org and its function in this way very easily. I strongly encourage you not to attempt to do this. Required fields are required for a reason.

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.

Set opportunity amount filed value as default value in related object field

I have a custom object FlightRequest for Opportunity object and there is an Amount filed both in opportunity and FlightRequest.
I want to set Opportunity's Amount filed value as default in FlightRequest's Amount Field. So whenever New Button clicked for FlightRequest, Amount input should already field with Opportunity's Amount
I m using Standard page layout not any visual force page layout and can not use it.
I saw there is an option to set default value for a field but Opportunity object is not shown in Select Field Type options
please advice how can i accomplish this
thanks in advance
This is possible with a "unofficially" supported technique (meaning everyone has been doing it for 10 yrs and while they say it's unsupported they'll never break it, too many customers use it) called URL hacking. Basically when they click the new button you'll pass the value for your field into the new record page dynamically based on the parent record. There is a good blog post tutorial on this. Give it a try and that should do what you need.
You need to set up a Master-Detail relationship between the objects, then you can setup the Amount field on the FlightRequest object as a formula field that references the Amount field on the Opportunity.
This should accomplish what you need to do. The Master-Detail relationship is essential for the cross-object reference of fields.

Resources