How to fix ClassCastException when using localized n-m relations with Smartedit? - sap-commerce-cloud

In Hybris 6.7.0, using I have a component that contains a localized list of another component.
I have been able to implement this using a n-m localized relationtype to implement a localized list that contains the component.
It works perfectly in CMS cockpit. However, in smartedit, it causes a ClassCastException.
The default converter seems to fail to recognize the collection type and therefore trying to cast the collection to a item model which causes the error.
Is there anyway to implement a localized collection that won't causes the exception in SmartEdit?
I have tried using a map and collection pair for the localization instead of a localized relation but the same problem occurred.
2019-3-7 - Updates: After a series of trial and error, I have realized that the LocalizedCollection will never be called because all localized attribute in Hybris is stored with an item type of MapType, which does not trigger the localizedCollection getter as it check if the localized attributs is of type CollectionType.
It seems to be a bug on SAP side. I am currently trying to come up with a temporary fix for the problem.

Related

PXSubstitute - CRActivity

I am currently attempting to create a new Activity type that has it's own maintenance screen.
The most logical approach I came up with was to create a new subclass based on CRActivity with the PXSubstitute flag to replace the stock value with mine that has the extra class types in it.
This works for displaying my new class on the screen however whenever I click on any of the items I always receive the message:
Error #97: A cache instance cannot be created for the type CRActivity.
For reference, here is how i'm defining my new class
[CRActivityPrimaryGraph]
[Serializable]
[PXSubstitute()]
[PXCacheName(PX.Objects.CR.Messages.ActivityClassInfo)]
[PXEMailSource]
public partial class CustCRActivity : CRActivity
{
.....
}
I took a step back and tried another approach by doing the same process but for CRPMTimeActivity. This causes all of the standard Class types to work but my new type gives the same type due to the CRActivityPrimaryGraph not knowing what my new activity type's nagivation is.
Has anyone ever created a new activity type such as this?
Updated 4/28
Below is a screenshot of what I was attempting to accomplish
I did finally get it to work but not quite the way I was hoping.
The initial error message was apparently build specific. After updating to a newer build that particular error went away.
What I discovered was even though I could Substitute CRActivity, most of the screens themselves were utilizing CRPMTimeActivity which has different attributes associated to it. CRPMTimeActivity is a subclass of CRActivity and the majority of the processes cast the activity to CRActivity.
A subclass of CRPMTimeActivity cannot be cast as CRActivity. Because PXSubsitute relies on the base class, this caused casting issues when attempting to add new activities.
In the end I had to create my own custom CRPMTimeActivity class and the base classes then customize the screens themselves to use my version of the activity builders.
The result is shown in the screen shot

How to find unused/non-dependent fields of any entity in CRM 2011?

I am trying to identify unused or non-dependent fields of any entity in Microsoft Dynamics CRM 2011. By unused or non-dependent i mean the field that is not used in any of the entity forms.
I have googled to find on the same topic but couldn't get the desired results. One link that i have come across also doesn't address this problem:
Finding unused CRM fields
First I should note that just checking if a field is not on a form does not mean it is not being used somewhere. There is a chance if you have a third party integration, or other logic running on an entity that it could be updating hidden fields. If you're unsure if there is data stored for an attribute you can do a retrieve request where your condition is that the attribute is not null. If nothing comes back then there is no data stored for that attribute.
Assuming that is already clear, what you'd want to do is utilize Dynamics CRM's Dependency Tracking to check for dependencies of individual attributes.
Here's the full article on Dependency Tracking for CRM 2011: http://msdn.microsoft.com/en-us/library/gg309749.aspx
The request that sounds most like what you're looking for is the RetrieveDependentComponentsRequest. This request seems to be the closest match according to what you're looking for and per the documentation:
Returns a list of dependencies for solution components that directly depend on a solution component.
For example, when you use this message for a global option set solution component, dependency records for solution components representing any option set attributes that reference the global option set solution component are returned.
When you use this message for the solution component record for the account entity, dependency records for all of the solution components representing attributes, views, and forms used for that entity are returned.
The basic steps to accomplish what you're looking for would then be:
Execute a RetrieveEntityRequest to retrieve all the attributes for a particular entity
For each attribute in the response, execute a RetreiveDependentComponentsRequest where you set the ObjectId to the MetadataId of the attribute, and the ComponentType to be 2 (attribute).
Parse the EntityCollection property on the response to see if any of the dependencies have a ComponentType of 24 (form).

Sharepoint Extenal List and Custom Field Types

I have an odd issue.
I have client that wants a sharepoint list what is populated from a WCFService. That part is working quite well.
I have a bdcmodel that is mapping the WCF data and I can create an external list from the bdcmodel as well so that is working fine.
The issue I have is that one of the properties in the model is actually a collection of entities called Attributes. The objects in this collection simply have 2 properties Name and Value so really they are just a key value pair.
The client wants to see the list of attributes of the parent entity in the external list. So there would be an Attributes column and within that column would be the list of attributes for each parent object.
Is there even a way to do this? I am looking into Custom Field Types, but it seems like these are really intended to be singular values.
How would I create a list within and external list?
Any help anyone can give would be great even if its just to tell me that there really isn't a stable way to do this so I can go back to the client and tell them we will need to build a custom list to support this because the OOB external list and custom fields and custom field types won't support this kind of nested listing.
I decided to set up the custom field as a string and when I get my collection in from the BdcModel I am serializing it to JSON and then passing it to the field. When the field is viewed in display, edit or new I have overridden the FieldRenderingControl and I am tiling the collection out that way.

How do I get mogenerator to recognize the proper type for Transformable attributes?

I have a Core Data model with a single transformable attribute. I also have this attribute use a custom NSValueTransformer, setup in the model properly.
When I use mogenerator to generate/update my machine and human files, the machine files for the entity containing this attribute always type the attribute to NSObject. In order for Core Data to use my custom value transformer, this type needs to be the type the transformer understands. Right now, I manually do this in the human file by redefining the property with the proper type. This does the job and gets the transformer working. However, I end up with several compile warnings regarding redefinition of the attribute.
One of the more recent releases of mogenerator specified in the release notes that transformable attributes are now supported. However, I haven't found any example syntax to enable this feature.
This should be better documented.
To set your generated attributes's type, select your desired attribute in the modeler and switch to the User Info tab. Then create a new element with a key of attributeValueClassName and a value of whatever you'd like.
Here's a screenshot:

Problem adding field to a custom list type in SharePoint

I have defined a custom list template type for SharePoint. I install it using VSeWSS 1.3 and everything seems to behave correctly.
I have added a custom action which will add additional columns (SPFields) to the list. However, every time that code executes it throws and ArgumentException with a 'Value not in the expected range.' error message. This behavior seems to be specific to custom types as suggested in this blog post.
Here is the relevant code (thisList is an instance of my custom list template type created using the browser interace) that tries to add a field to the SPFieldCollection of thisList:
SPFieldType fieldType = Format2SPFieldType(format);
SPField field = new SPField(thisList.Fields, fieldType.ToString(), fieldName);
thisList.Fields.Add(field);
The last statement (thisList.Fields.Add(field)) throws the following exception:
Message "Value does not fall within the expected range."
at Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName, Boolean bThrowException)
at Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName)
at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op)
at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXml(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op)
at Microsoft.SharePoint.SPFieldCollection.Add(SPField field)
This same code executes just fine if the SPList item is the base list type (built-in custom list).
Are there any fields that need to be set explicitly in the CAML and using the AddFieldAsXml() method directly to make this code work with custom list template types?
Update: I should also mention that the fields are actually created in some instances even though the call throws an exception!
Turns out that this was caused because calling thisList.SchemaXML put the SPList object into a state that I wasn't able to recover from! Getting a new reference to the same SharePoint List, e.g., SPList newList=thisList.ParentWeb.Lists[thisList.ID] solved the issue!
What is the Type of Field you are trying to add? is that an Internal field or a Custom Field type, what does this Function Format2SPFieldType return?
If it is a Inbuilt field can you try adding with the
thisList.Fields.Add("DisplayName", SPFieldType.Integer, false);

Resources