Hybris Cant Access comments filed of Customer - sap-commerce-cloud

I am new to Hybris. My Requirement is to select all customers who have not left comments. I found that Comments have an author field and that I joined two fields of Customers and Comments. Also, I find out that Comment has a comment field which is a collection of comments. The problem is that I can't access to comment field to check if is it null or not.
SELECT * FROM {comment AS ct JOIN customer AS cr ON {ct:author}={cr:pk}} WHERE
{ct:comment} IS NOT NULL
the exception that hac gives
Exception message: cannot search unknown field 'TableField(name='p_comment',langPK='null',type=comment)
it says there is no comment field

Comment model has text fields, I can't see Comment field on it. Use below query:
SELECT * FROM {comment AS ct JOIN customer AS cr ON {ct:author}={cr:pk}}
WHERE {ct:text} IS NOT NULL

Related

Create a Report in SAP Hybris to Fetch Employees based on a User Group

I need help for creating a report in SAP Hybris which essentially would be used for fetching out the names of "Employees" not "Customers" based on the "User Group" they're assigned. For example : X employee has usergroup : "admingroup". Like that I would need all the Employees with the respective usergroups. Could anyone please help me with a flexisearch query for the same to start with ? I would really appreciate that ! Thank you
I am still new to SAP Hybris and I have seen a lot of other reports but wanted to try this out.
You can use the string_agg()-method to list up the user groups, it's mentioned here: How to concatenate multiple rows in flexibleSearch query in Hybris
If the method doesn't work you can try to replace it with group_concat.
You also need to join the Employee with the PrincipalGroup. You can access the employee's user groups with the attribute groups:
SELECT
{e:displayName},
string_agg({g:locName}, ', ') AS groupNames
FROM {Employee AS e}
JOIN {Employee.groups AS g} ON {g:pk} = {e:pk}
GROUP BY {e:pk}, {e:displayName}
for this report it require join with PrincipalGroupRelation as there is no direct relation with usergroup and employee.
select {user_group:uid},{user_group:locname[en]},{emp.uid},{emp.name} from {Employee as emp JOIN PrincipalGroupRelation as group_rel ON
{group_rel:source}={emp:pk} JOIN UserGroup as user_group ON {user_group:pk}={group_rel:target} } where {user_group.uid}='customersupportagentgroup'

Adding a field to a table that is the result of a query to another table

In MS Access 2010, I have two tables - one with Candidates and one with Package Actions. The Actions are associated with the Candidates via the CandidateID field, which is an autonumber in the Candidates table. The Actions table has a date field for each action. I have a field in the Candidates field that I would like to display the action type of the most recent action associated with that particular candidate, but can't seem to figure out how to do it. I've tried implementing a subquery as a default value:
SELECT TOP 1 ActionT.ActionType FROM ActionT WHERE
(((ActionT.CandidateID)=13))
ORDER BY ActionT.DateCompleted DESC;
Obviously, this query on its own only returns the most recent action for candidate 13 but ideally I would like to replace the =13 with =CandidateID but I can't even get the field to populate with the result of the query as is. I've also tried using DLookup but got an error while trying to make that the default value. I've also tried using the button "Modify Lookups", pasting the query and the DLookup directly into the cell, and trying to change the type of the field from "Text" to "Calculated", all to no avail.
Novice MS Access user here, so I appreciate any extra explanations y'all may have.
Thanks In Advance.
EDIT:
Just to be clear, I'm not looking for a query, per se. I want to know how I can make the result of my query above always be the value of a field in the candidate table. (If my code above needs corrections, I'm open to that, but that isn't really my question.)
Example: Candidate A has several actions in theActionTable associated with him. They are ResumeRecieved, ResumeReviewed, and Interviewed. The date associated with Interviewed is the most recent, therefore in the CandidateTable, the status for Candidate A should be "Interviewed." We then decide to extend an offer, so we add an action to the ActionTable "OfferExtended."
The Status field in the CandidateTable for Candidate A should automaticaaly update to read "OfferExtended"
Inside your main SELECT STATEMENT, you need to have a nested SELECT STATEMENT descendingly ordered by DateCompleted to get the most recent DateCompleted for each CondidateId.
Below should do the trick for you:
SELECT con.Id,
con.Name,
(SELECT TOP 1 ActionType FROM ActionT
WHERE CandidateId = con.Id ORDER BY DateCompleted DESC) AS ActionType
FROM Candidates AS con

add value from text field to look up field crm plugin

thank first all to helping me, out
I have got a big problem
I trying to run a post operation plugin in crm 2013
I have got, to Entities One is "account" and the other one is "sales"
My problem is :
The filed in entities account is lookup filed
And the filed in sales is text filed
The value from the sales Test filed I have to add in the look up filed
I have allready retrieve the value from the sales test field
Only problem is I can’t add the value in the look up:
get an error message.
It would be appreciated if you can share the error message which you are getting.
Assuming that you are trying to set the primary contact for the account, I would have coded as follows,
Entity account=new Entity("account");
account.Id=;
account["primarycontactid"]=new EntityReference("contact",);
service.Update(account);
In this case i again assume the text value which you have retrieved is a Guid value. If not, get that value from CRM using a service.Retrive() or service.RetrieveMultiple() methods and do it as above.
Hope this helps!!!.

Dynamics CRM 2011 SQL MetadataSchema Primary Name Attribute

I am trying to create a custom Audit summary report based on a date range that needs to be emailed nightly. I've got most of it working, but need some help with getting the primary name/field/attribute for a referenced entity. I noticed in the Audit view for a referenced entity, the data is stored like 'systemuser;'. What I would like to do is grab the Primary Field (Primary Name, Primary Attribute, whatever it's called) to display on the report. Does anyone know how to find the Primary Name attribute for an entity using the MetadataSchema views in the CRM SQL database? I have found the Primary Key field by looking at the MetadataSchema.Attribute.IsPKAttribute field, but I don't see anything for the Primary Name field.
Also, I am grabbing the current values from the entities if there are no following audit entries. For the lookup fields (like owner or customer) how can I tell from the Metadata what field stores the ObjectTypeCode? For example, if I was looking up the customer on a sales order, I know I can look at CustomerIdType field to find the ObjectTypeCode, but I need to find that the field is called CustomerIdType from the metadata.
If anyone has any good references on the Metadata from the SQL side of CRM, I would greatly appreciate it.
SQL query to get primary fields for all entities
SELECT e.Name as 'entity', a.Name as 'primary field'
FROM [dbo].EntityView e
left join [dbo].AttributeView a on e.EntityId = a.EntityId
where (a.DisplayMask & 256) > 0 --256 is for primary field
order by e.name
There are two cases to get object type code of lookup
append Type to field name (i.e. CustomerIdType)
if above is not available, get it from AttributeMetadata
SELECT ReferencedEntityObjectTypeCode
FROM [Discworld_MSCRM].[dbo].[AttributeView]
where name = '<field name>' and entityid = '<entity id>'
I'm not sure what exact rules are for Type fields to exist

CRM 2011 How to select the related entity fields in Advanced Find

I am using CRM 2011 Advanced Find on Account Entity to find the Incident CreatedOn Date where Incident is connected to Account.
But when I go to Edit columns it does not give me option to select the Incident CreatedOn Date (Because Advanced find query is on Account Entity). Is there any way to select the Related Entity fields on in search.
You wont be able to add the Incident.CreateOn in the Edit Column from the Account entity as you can only add lookup fields (resulted from a N:1 relationship between account and the other entity).
As the Account and Incident have a 1:N relationship, you should be able to add the account column to the Incident columns as stated by Pedro Azevedo. The image below shows you how to do it:
Notice that the Record Type will show you a list of the lookup fields you have in the Incident entity and to which entity is relates to - in this case, Customer is the relationship name in the Incident entity and Account is the related entity.
Cheers, dimamura
Try do this in Incident Entity. You can filter and add columns in both entity.

Resources