I need to find all the documents in a database that the field wfsCurrApp contains a given role. in the search bar I entered field WFSCurrApp contains [Finance] but I get the error that the query is not understandable. If I change it to field WFSCurrApp contains "[Finance]" the query runs but returns nothing.
What I'm ultimately trying to get done is something like this because the user may possess several roles in the target database I believe the issue is the [] as that is used to delimit dates, but ????:
var uRoles = thisDB.queryAccessRoles( context.getUser().getDistinguishedName());
var userRoles:String = "";
var it:java.util.Iterator = uRoles.iterator();
while (it.hasNext()){
var thisRole = it.next()
if (userRoles == "") {
userRoles = thisRole
}else{
userRoles = userRoles + " OR " + thisRole;
}
}
tmpArray[cTerms++] = "(FIELD WFSCurrApp CONTAINS (\"" + userRoles + "\"))";
Edited:
tmpArray has this in it
(FIELD WFSCurrApp CONTAINS ("[Finance]")) when the user has a single role and
(FIELD WFSCurrApp CONTAINS ("[Finance]" OR "[WFSAdmin]")) if the user has multiple roles. Neither of these return any documents that I know have the role [Finance] in the Current Approvers field WFSCurrApp.
The query has a number of other tags so tmpArray is split and each element is seperated with an "OR". This is the final query
(FIELD WFSCurrApp CONTAINS "Barney Rubble/Workflo Systems") OR (FIELD WFSCurrApp CONTAINS ("[Finance]"))
the query returns the documents where WFSCurrApp contains Barney but not the ones where Barney's role is [Finance] and there are some that Barney is not in the current approvers but he possess the role [Finance] and that role is in the Current Approvers.
The query returns without error and returns the documents where Barney is listed in the Current Approvers so there are no errors raised, just does not find the matching role.
Started Working correctly so guess it might have been an index update issue
Related
For table cmdb_rel_ci, I want to retrieve unique parent.sys_class_name with count for "type=In Rack::Rack contains". I am doing practice in out of the box instance.
At table level URL is as below:
URL
I want to retrieve result from above URL with my below script.
var count = new GlideAggregate('cmdb_rel_ci');
count.addQuery('type','e76b8c7b0a0a0aa70082c9f7c2f9dc64');// sys_id of type In Rack::Rack contains e76b8c7b0a0a0aa70082c9f7c2f9dc64
count.addAggregate('COUNT', 'parent.sys_class_name');
count.query();
while(count.next()){
var parentClassName = count.parent.sys_class_name.toString();
var parentClassNameCount = count.getAggregate('COUNT','parent.sys_class_name');
gs.log(parentClassName + " : " + parentClassNameCount );
}
The issue is I am getting parentClassName empty.
Try this instead:
var parentClassName = count.getValue("parent.sys_class_name")
Since it's a GlideAggregate query (instead of GlideRecord), the query being issued isn't returning all of the fields on the target table. With GlideRecord, dot-walking through a reference field (e.g. parent.sys_class_name) automatically resolves that referenced record to provide access to its field values. This is made possible by the fact that the driving/original query brought back the value of the parent field. This is not happening with GlideAggregate. The query in this case basically looks like:
SELECT cmdb1.`sys_class_name` AS `parent_sys_class_name`, count(*)
FROM (cmdb_rel_ci cmdb_rel_ci0 LEFT JOIN cmdb cmdb1 ON cmdb_rel_ci0.`parent` = cmdb1.`sys_id` )
WHERE cmdb_rel_ci0.`type` = 'e76b8c7b0a0a0aa70082c9f7c2f9dc64'
GROUP BY cmdb1.`sys_class_name`
ORDER BY cmdb1.`sys_class_name`
So, you actually have access specifically to that dot-walked sys_class_name that's being grouped, but not through the dot-walk. The call to getValue("parent.sys_class_name") is expectedly resolved to the returned column aliased as parent_sys_class_name.
That being said, what you're doing probably should also work, based on user expectations, so you've not done anything incorrect here.
I am using Odoo v10. While scanning a barcode, a string contains some characters of a char field value. For example,
A field value ('tracknum') = "20171103"
Search the field by entering a string "xxxxxx20171103" or "xxxx20171103yyy"
is there any way to do it?
I have modified the search view :
<field name="tracknum" string="Tracknum" filter_domain="..."/>
How to dig out related records?
You can create an auxiliar computed field like this
custom_name = fields.Char(
string='Custom',
compute='_compute_custom_name',
search='_search_custom_name'
)
#api.multi
#api.depends()
def _compute_custom_name(self):
''' The field has to be a computed field
You do not need to do anything here
'''
pass
def _search_custom_name(self, operator, value):
''' Actually this converts a domain into another one.
With this new domain Odoo can search well
Arguments:
* operator: if you are searchig words it is going to be ilike
* value: the string ro search
The method could return something like this
* [('id', 'in', id_list)]
'''
all_records = self.search([]) # recordset with all the values of the current model
ids = []
if operator == 'ilike':
ids = all_records.filtered(lambda r: r.tracknum in value).mapped('id')
return [('id', 'in', ids)]
Then you can add this field to the search view like this:
<field name="custom_name" string="Tracking Number" />
Keep in mind that it is not a stored field, so it is going to be very inefficient. And you should iterate over all the values each time you want to make a search.
Once you have added the field to the search view it shoul look like this, Tracking Number should appear in the field name
I have Documents table and Signs table. Document record can be related with many records in Signs table.
Now, I want to get all records of Documents table when document ID appears in Signs table.
Here I get all documents:
var documents = (from c in context.documents select c);
Here I get all my signs and save into List:
var myDocuments = (from s in context.signs where s.UserId== id select s.ID).ToList();
This list contains collection on document ID.
And here, I'm trying to get all documents that exists in myDocuments list:
documents.Where(item => myDocuments.Contains(item.ID));
But, when I do .ToList() allways return all records (in database only exists one compatible record)
What is wrong in LinQ statement?
The problem is that this statement doesn't modify the contents of documents, it merely returns the results (which you're not doing anything with):
documents.Where(item => myDocuments.Contains(item.ID));
documents is still the full list.
Change this line to something like:
var matchingIDDocs = documents.Where(item => myDocuments.Contains(item.ID));
And then use matchingIDDocs in place of "documents" later in your code.
I have two columns one is from user and other is to user. now i am checking if current user is in from user or to user. i am querying like the following.
var matQueryFrom = new Parse.Query(Parse.Object.extend("VRMatches"));
var matQueryTo = new Parse.Query(Parse.Object.extend("VRMatches"));
matQueryFrom.equalTo("FROM_USER_OBJECTID",user.id);
matQueryFrom.include("TO_USER");
matQueryTo.equalTo("TO_USER_OBJECTID", user.id);
matQueryTo.include("FROM_USER");
var mainQuery = Parse.Query.or(matQueryFrom, matQueryTo);
i want to get from user if the current user matched to user. OR i want to get to user if the current user matches from user. How can i achieve that or what i am doing wrong?
You need to read the Parse documentation becuase it clearly says:
Note that we do not, however, support GeoPoint or non-filtering
constraints (e.g. near, withinGeoBox, limit, skip,
ascending/descending, include) in the subqueries of the compound
query.
You might be able to add both of the include constraints to the final compound query. Maybe this will work but obviously you will not be able to distinguish which sub query returned which row as the results of both sub queries were Ored together:
var matQueryFrom = new Parse.Query("VRMatches");
var matQueryTo = new Parse.Query("VRMatches");
matQueryFrom.equalTo("FROM_USER_OBJECTID",user.id);
matQueryTo.equalTo("TO_USER_OBJECTID", user.id);
var mainQuery = Parse.Query.or(matQueryFrom, matQueryTo);
mainQuery.include("TO_USER");
mainQuery.include("FROM_USER");
I have a Document table and a Version table. Both have identical information. Whenever a document is created it is inserted into the document table. Whenever that document is then edited a line is added to the Versions table.
It has a field dateApproved which will be null until it is approved. I am currently working on a MVC 4 Approval page and I have never touched linq before and it needs to be done in linq.
How can I join these two tables Document/Version and only show items where dateApproved is null?
from v in Versions
select v
from v in Document
select v
EDIT #1
A user adds a brand new document, this document is then added to the document table. At this point the document needs approval. The dateApproved field in the Documents table is null. Lets say this document gets approved, then the user makes a change and since this document already exists a line is added to the Versions table. Now this document exists in both tables the original document having a revision 0 with a dateApproved, and the Versions table have a revision 1 with a dateApproved as null.
What I need is the documents where the dateApproved is null weather this null is in the Documents table or the Versions table. After it is approved we leave the line in the Version table, and update the line in the Documents table with the approved version.
The key primary key is DocumentID.
EDIT #2
Thanks to Peter Kiss it is now displaying all the files that need to be approved. There is one more hiccup I am running into. It is returning 3 results which is correct. 2 files are brand new and 1 has been edited.
The 2 brand new files it displays the information correctly as from the documents table. The edited file it is displaying the information from the documents table but I need the info from the revisions table. Is it possible to make it return the version table information if the item exists in the version table and return the document table information if it does not exist in the version table (ie brand new).
Hope I explained that properly.
var documents =
ctx.Documents
.Where(x => x.dateApproved == null
|| x.Versions.Any
(y => y.dateApproved == null));
The documents variable will contain only those documents which are having unapproved versions. Then when you iterating through this collection the current document can reach it's Versions (all) through a navigation property called Versions. In that collection you can filter the unapproved versions.
All this only happens when the mapping is set up correctly (aka foreign keys) in your context.
After Edit #2
class DocumentToApprove
{
public string Name { get; set; }
/* other stuff */
public int version { get; set; }
}
var documents = ctx.Documents
.Where(x => x.dateApproved == null
|| x.Versions.Any(y => y.dateApproved == null));
var toApprove = from d in documents
let v = d.Versions.FirstOrDefault(y => y.Approved == null)
select new DocumentToApprove
{ Name = d.Name
,
/* other stuff */
Version = v == null ? 1 : v.VersionNumber
};
Select only records which are having dateApproved is null. and collect it in some kind of list listofVersions.
var listofVersions=(from v in Versions
where v.dateApproved==null
select v).ToList();
You can do the same for Document. Just substitute Version with Document.
Note: I just collect it with var to make it simple. You can create a list of Versions/Document if you wish.