Creating blank dummy Components which contain mandatory Fields with the SDL Tridion 2011 Core Service - tridion

I wanted to create a blank Component in SDL Tridion 2011 using the Core Service. The only information I have at the start of the process is the Schema URI. The Schema may contain any kind of field (text, rtf, number date, embedded etc), some of which may be mandatory.
I understand that for the mandatory fields, I will need to save some dummy value in them, and this is acceptable as they will be changed manually later.
How can i achieve this?

First - you make sure all fields are set to optional in the schema, otherwise this will never work.
Second - You save.
When an optional field has no value, it will have no XML representation. If you have a schema that defines a component like this:
Field1
Field2
Field3
When all fields are optional and you save a value in Field 2, Tridion will store the following:
<Content xmlns="yourNamespace"><Field2>SomeValue</Field2></Content>
If one of your fields is not mandatory, then you'll have to provide a value. If you're using the CoreService then you can use ReadSchemaFields class to get the fields and some information about them - what type, mandatory/optional, etc.

Looking at your question/requirement to understand what you're exactly looking for, so we can answer the best possible and relevant.
Are you asking for "How can you write a generic code for component creation using core service?" instead of creating a component with a specific schema knowing all the fields upfront.
If that is what you are looking for, here is what you need to do:
You need to read the schema fields with CoreService (since you know the schema URI)
Now you know what type of fields (embedded/component link etc) you need to create content for
use the links pointed by "Puf" in his answer.
Please note that, if the field is marked as required in Tridion Schema you must have to fill a value and it has to match the field type defined in schema.
Reading schema fields via Core Service sample code can be found here

Updating a Component's field through the Core Service is already answered here: Updating Components using the Core Service in SDL Tridion 2011
That post points to a helper class you can find here: Updating Components using the Core Service in SDL Tridion 2011
If those don't help you in creating a Component, I suggest you post your code instead of asking us to write it for you.

We ask about use case, because code to fill in specific fields for a specific schema only works in one environment. Code that can automatically determine fields is re-usable.
If the use case is for an Tridion setup that has Inline Editing (Experience Manager or SiteEdit), then the correct approach is content/component types. These define a reference component with "junk defaults," instructions to the author, and even save location context.
If the use case is to allow authors the ability to create dummy components, this is out-of-the box with:
CTRL+C
CTRL+V
One-time setup required to create a "reference component." Of course we can mimic this behavior (in case "Copy of Untitled" isn't an appropriate name) by copying items with the core service.
In that case, I'll also do a copy--see a general solution for creating Tridion items using the Core Service.
Fields that require a default can have an actual default in the schema.
"Junk values" don't help authors much, always consider good defaults such as an appropriate selection or instructions in the case of fields (maybe). A 10 second change costs development practically nothing, but impacts all future components and the authors that create them.

Related

CodeFluent Entities Add Runtime Design Attribute to False

Now that the site blog.codefluententities.com is down, there is no place to get answers to frequent questions.
Even the FAQ's and blog at their main website is poor and lacks of any search tool.
At the "knowledge center" you can try to search some basic questions but you'll need to custom search at google using the website: key.
I've finally found a clue about my last failure using this old promising tool at:
https://www.softfluent.com/product/codefluent-entities/knowledge-center/json-serialization-D2715E9D140C-A6080529C80C
but the key link is pointing to a lost domain and that's the end of the road.
My question is solved at:
CodeFluent Entities adds a TypeConverterAttribute that allows to convert an entity to string using the EntityDisplayName property. Json.NET detects this attribute and wrongly uses it to serialize the entity to JSON. There are 2 solutions:
Remove this attribute if you don't use it by setting Add Runtime Design Attribute to False
Use the Json.NET aspect to generate specific Json.NET attribute on generated classes and properties
but there's no information about how to do it.
As SoftFluent states, questions can be post to SO adding the codefluent tag, but user's community is poor at knowledge of the product and developer team #meziantou is overloaded
I really hope this project does not fail as it was one of my last bets to a hidden-source company and pray at every out-of-date free-license internet connection dependent renewal for their server not being closed.
CodeFluent Entities adds a TypeConverterAttribute that allows to convert an entity to string using the EntityDisplayName property. Json.NET detects this attribute and wrongly uses it to serialize the entity to JSON. There are 2 solutions:
Remove this attribute if you don't use it by setting Add Runtime Design Attribute to False
The following configuration will prevent CodeFluent Entities from generating [System.ComponentModel.TypeConverterAttribute(typeof(CodeFluent.Runtime.Design.NameTypeConverter))] on generated classes:
<cf:producer name="Business Object Model (BOM)" typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom">
<cf:configuration addRuntimeDesignAttributes="false" ... />
</cf:producer>
You can also use the modeler to set this attribute.
Use the Json.NET aspect to generate specific Json.NET attribute on generated classes and properties
If you need to preserve the TypeConverter, you can instruct CodeFluent Entities to add custom JSON.Net attributes on generated classes and properties using the following aspect. The code and usage sample is available on GitHub: https://github.com/SoftFluent/CodeFluent-Entities/tree/master/Extensions/SoftFluent.Json.NET/
To make you more confident : yes this SO tag is still monitored at SoftFluent. There is also the support[at]softfluent.com mailbox that allows to contact the support team directly. The product is still supported and fixes are published when bugs are reported to us. We are preparing a new version targeting .Net Standard 2.0 but will still support the existing version as is. I can not provide yet any timeline though for this new version.

How do I find out a field's type information for a 'record' in appmaker in Server script?

I'm trying to create a re-usable script for capturing record changes onSave with Server-side scripting. To do that, I need the model information for a given table, including what type each field is.
I have figured out how to get the model for my table and details for the fields:
var table = "Clients";
var myObject = app.models[table];
// Dump the properties of the 2nd field in the model
console.log("Field 2 properties: " + JSON.stringify(myObject["L"]["fields"]["1"]));
I see this:
{"name":"Client",
"key":"zzzkS1spSPKkRXMn",
"displayName":null,
"description":"Short name for client (must be unique)",
"type":{},
"required":false,
"uid":false,
"defaultValue":null,
"minLength":0,
"maxLength":null,
"integer":false,
"sortable":true,
"minValue":null,
"maxValue":null,
"regexp":null,
"regexpError":null,
"possibleValues":null,
"aggregationType":null
}
"type" looks like an empty property here and I can't seem to figure out how to get any reference to it to tell me what I need.
How do I get usable type information for a given field in a model?
Right now, App Maker doesn't expose an API to access the model metadata.
You snippet is actually accessing App Maker's internal state and might break in future releases (the "L" property is actually obfuscated by a JS compiler and not designed to be accessed from user land).
We know this kind of meta-programming is handy and this is something we might add in the future based on user feedback. Please feel free to submit a request feature in our issue tracker (https://developers.google.com/appmaker/support).

2sxc List.Presentation in General View

I have an entity type "Post" and I would like to create a view that will show one random Post with a given category. I created a Data pipeline that grabs all posts and I created a view with ListPresentation = a "TemplateSettings" entity type that lets me choose categories.
I planned to use the Razor template to filter the items for those matching the categories in List.Presentation.Categories. But, I can't seem to reference List.Presentation.Categories. I get an error that System.Collections.Generic.List doesn't contain an entry for "Presentation". When I use #ListPresentation, the whole object in null... so #ListPresentation.Toolbar, etc. all throw errors, despite me having set a "Demo Item".
Can anybody see what would be wrong with this setup? How do I reference List Presentation stuff in Razor?
Thanks.
I figured this out... The direct thing seems to be "ListPresentation", but the snippets use "List.Presentation". Still, it wasn't working in my case because I was using a data query that didn't include the module data. So, I had to modify that query to include the module data as well as the full list of entities, regardless of the module. Then, I got the full list from one data stream, and the ListPresentation fields were available.
Note also that you can use ListContent.Presentation - that would be the newest, most consistent API which always places Presentation information as a property of the entity it's describing.

What is Id parameter on CoreService2010Client Localize method

I need to localize a bunch of content components for testing to prove the different sites I have created for each support language is pulling from the correct content.
I see Core services (CoreService2010Client) has a method Localize, but, in general, how do you use it? Specifically, I'm wonder if calling it just localizes the component and then I can modify the component? Do I still need to call CheckOut and CheckIn on the TCM Id of the language item?
public RepositoryLocalObjectData Localize(string id, ReadOptions readBackOptions)
Once I get all the components localized and acceptance testing passes, what is the easiest way to UN-Localize everything I did?
The id parameter stands for "The identifier of the item (TCM URI or WebDav URL)". This means that you are localizing the item in the context of the Publication you specified as part of that ID.
For unlocalizing you can use method RepositoryLocalObjectData UnLocalize(string id, ReadOptions2010 readBackOptions) on the same client interface ICoreService2010.
You can find the API docs on SdlTridionWorld.com (log in) -> Downloads -> Documentation -> SDL Tridion 2011 (or SDL Tridion 2011SP1).
Localizing an item has nothing to do with CheckIn CheckOut. Localizing will simply create a 'local copy' of that item, which later on you can choose to modify, save, etc, or unLocalize.

Add extra field in story content type using hook without CCK

I want to add extra field in story content type using hook, I don't want to use CCK, because am trying something different.
Please tell some suggestion with hook method.
If you do not use CCK, you will have to create your database table and code to add the form field, validate the form field, capture the data and save it in your field. I know cck can be a monster, but it does all this for you. I'd be happy to give you more info on all of this, but it is quite lengthy
There are lots of reasons that you may want to do this without CCK or Fields, and the best example is found at the node_example module in the examples project which can be found at: http://drupalcode.org/project/examples.git/tree/refs/heads/6.x-1.x:/node_example. You can also view the documentation on api.drupal.org.
The short version is that you're going to have to define your own node type using hook_node_info() and then define all the hooks for _load(), _insert(), _update(), _delete(), _access(), _validate(), and _view() in addition to defining your schema in your hook_schema and managing your tables on your own.
Sadly there is no good example for Drupal 7 as the node_example module for 7 was converted to use fields instead of the hooks listed above, which are still fully documented on api.drupal.org (they do now typically act on an array of nodes instead of a single node, but are otherwise identical).

Resources