I am trying to fetch group by data in Django. I`m using postgres database
How I Can write Django query like this SQL query:-
SELECT id FROM table_name WHERE name=%s GROUP BY name"
I am trying with Model.objects.filter().values('id').annotate(count=Count('name')).order_by('name') but not get unique name`s id in QuerySet
and also try
Product.objects.filter(id__in=RawSQL(f"SELECT id FROM product_product WHERE name=%s GROUP BY name", (key,)))
but got error
"column \"product_product.id\" must appear in the GROUP BY clause or be used in an aggregate function\nLINE 1: ..._product\" WHERE \"product_product\".\"id\" IN (SELECT id FROM pr...
model.objects.filter(user=id).values('name').annotate(dcount=Count('name')).order_by()
You need to specify a filter value when u want to filter data from the model.
The value field takes in the value you want not the id
Then you annotate it.
For more information you can read the django documentation: here
Related
I am inserting record with scan_date as <Today_date>T00:00:00.000+0000, but I am not able retrieve the same using scan_date = TODAY (SOQL).
example:
There is record with scan_date = "2022-01-10T00:00:00.000+0000", but the record is empty when I queried
SELECT Id FROM <Table_name> where Scan_Date__c=TODAY
But I am retrieve the same data by using query
SELECT Id FROM <Table_name> where Scan_Date__c=YESTERDAY
BTW I am using JsForce with nodeJS.
I solved using DAY_ONLY()
I used the DAY_ONLY() with Scan_Date__c to just compare the date and ignore the time.
SELECT Id FROM <Table_name> where DAY_ONLY(Scan_Date__c)=TODAY
Reference
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_date_functions.htm#
I'm trying to make Saved Search which has Transaction fields that I want to join any other type's fields.
When I make Criteria, Result in Saved Search, I realized there is limitation to bring certain field.
I know the Type & Internal ID, so I used formula(numeric) and insert custom_item.realamount(This is actually what I want to know). But this wasn't show a value.
How can I make these two types to join each other?
There is no field in Netsuite called custom_item If you are trying to join a custom item field on a transaction search formula field then you'd be looking at a join like
{item.custitem_uniquepart_}
Where _uniquepart_ is either an integer if the custom field was created without a custom id value or it's the value entered for the id field of the custom field.
I'm working with PencilBlue, and I'm having trouble with the custom objects Id's. The "name" field is used as an Id, but I would like it to be just a regular field and have an "id" field as identifier.
How could I achieve this?
PencilBlue cofounder here. Each custom object will have a unique id field supplied from the MongoDB database. You can also create another form field for a non-unique name and use the name field for UID.
I am trying to add a search filter to a search in SuiteScript. What I want to filter is the date a custom record is created. The search is off a job (or Project) record, but the custom record is connected to the job (this needs to be off the job for other reasons).
In the UI this would like like: CustomRecordName : Date Created (and as a filter you would select the filter you want, such as within this fiscal quarter).
I know the syntax:
new nlobjSearchFilter(fieldId, join, operator, value1, value2);
I went to the custom record and the "Date Created" fieldId is 'created'. My Custom record's id is: customrecord301.
Here is what I have for my specific case:
filters.push(new nlobjSearchFilter('created', 'customrecord301', 'within', 'thisfiscalquarter'));
I get the following error:
An nlobjSearchFilter contains an invalid join ID, or is not in proper syntax: created.
What am I missing/doing wrong?
The join parameter should be the ID of the field you are joining through instead of the record type you are joining to. Instead of "customrecord301", you need the ID of the list/record field on the Project (job) record.
You don't need to put any value in 'join' until and unless you are executing a joined search.
Please try this
filters.push(new nlobjSearchFilter('created', null, 'within', 'thisfiscalquarter'));
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