How to get localized name of an attribute of an item type in Hybris? - sap-commerce-cloud

I need localized name of the field of a new itemtype I created, can someone please point out if there are any existing service/utility available for achieving the same.
Thanks in advance.

You can use below util class:
de.hybris.platform.util.localization.Localization.getLocalizedString("type.MyItemType.myProperty.name");
Above function using jalo session locale. If you want to get for any translation, you need to create your own function. You can check above function implementation and create your own function.

Related

how create new Employee in hybris programmetcally

I am unable to create new user with below code :
final EmployeeModel empl=new EmployeeModel();
empl.setUid("test");
modelService.save(empl);
Also, don't do this: new EmployeeModel();
You should always use the ModelService to create new instance of ItemModel:
modelService.create(EmployeeModel.class)
Using modelService, it will go through any Interceptor that's define for this type and then, could initialize default value for your item. When your using the new operator. It won't set the default value, and can result in the kind of error you are facing.
This code works in an hybris out of the box.
You have probably customized the employee type and added mandatory fields.
Check the error detail, you will probably find out the field you missed.

How to change the display field to use when use jdl?

When use jhipster entity generator by console a question like follow allows to change the display field on frontend:
When you display this relationship with AngularJS, which field from
'user' do you want to use? (id)
It is possible to make the same with jdl?
Edited
Ok, It appears that nobody has this problem, or maybe there aren't anybody in home?
So, I'm going to explain it. Let's suppose this scenario:
Create two (or more) entities with relationship with the console.
Choose a different field from id to manage the front-end.
Test the project (it works fine).
Export the model to jdl file
Import the jdl file, with no changes, in another new project.
Boom! The UI comes back to Id reference.
Is there any option to resolve it, or is this resolve in other tools like uml import? Future plans?
Resolved
Reading the documentation in detail, I've found a solution:
"Declare the field you want to use to display a relationship in AngularJS.
To do that you must add the field name between () after the injected field name."
Resolved
Reading the documentation in detail, I've found a solution:
"Declare the field you want to use to display a relationship in
AngularJS.
To do that you must add the field name between () after the injected
field name."

Adding custom Field to doctrine object in Controller

I have a symfony2 Project with an Account entity. It has two attributes id and description.
In my Controller i want to enrich my doctrine Objekts with a further field called name. This property will not be persisted and is only used in my twig template. In twig i want to use {{Account.name}}.
How can i assign values to my objects in my controller that can be used in the twig file?
Thanks, greets mike
oh, its actually so easy :-)
i can simply add
$entity->myproperty = "whatever i want";
and then in my twig template i use
{{entity.myname}}
thanks anyway... i did not know that i can assing properties to my objects like this.

Formula referencing parent doc works in computed field, not as default value

Following on from this question: Referencing parent field on document creation I'm using the formula for the default value for a name field.
IfError(#IfError(#GetDocField($ref;"ProductFamilyManager");
#GetDocField(ParentUNID;"ProductFamilyManager"));
"")
This works when it's a computed field, but not when i change it to be editable with a default value formula.
Any ideas how I can get the field populating with the default value?
The best way of doing this is to use #InheritedDocumentUniqueId. You need to enable inheritance to make that function available, but you don't actually have to inherit any of the parent values.
You should definitely not have to be using two different techniques and #IfError to get this done. And btw: did you know that #IfError is obsolete as of Domino 7?
It may not be supported but just to be sure, has the parent doc been saved before you create the response doc?
Assuming that's not the problem, the alternative is to use the "inherit field values from parent doc " option, which will pass a value from the parent doc to the response doc on creation. I may have the wording wrong but the option is on the form properties dialog in Designer.

Why the OnWorkflowItemChanged is different between List and document library?

I am doing a workflow for a document library. I put a OnWorkflowItemChanged, and I want to get the value of the column which is changed. I use the workflowProperties.Item["name"] and use the afterProperties. But when I use the workflowProperties.Item["column name"], I still got the original value. When I use the afterProperties, it's NULL.
Then I make another workflow that is the same as above for a list. I can use the workflowProperties.Item["column name"] to get the new value in OnWorkflowItemChanged.
Has anyone come across this problem before? Can you give me some help?
The question seems to mix up Item with ExtendedProperties. As to why a difference is seen on a List/Document Lib, it might have something to do with versionining or perhaps the internal serialization is different. Anyway, some of my experience is outline below. I hope it may be of use:
Use the GUID (as a Guid object, not a string) to access the Before / After ExtendedProperties field. Using the Display Name in the ExtendedProperties will not work. The documentation on it is wrong. You can use SPList.Fields to go from Display Name to Column ID (Guid).
I bind all "Before" to MyWhatever_PreviousProperties and all "After" to MyWhatever_Properties, only accessing MyWhatever_[Previous]Properties after the appropriate event(s)).

Resources