I am very new to SAP Commerce and have been experimenting with Flexible search. Some queries work i.e and some dont.
Below one works fine.
1) Select * {User} SELECT {user.pk} FROM {User AS user}
2) SELECT {user.pk}, {ItemType} FROM {User AS user}
However when I am fetching email or uui, it is just not working.
1) SELECT {email} FROM {User AS user}
2) SELECT {originaluid} FROM {User AS user}
I have tried with {p_ as well which didn't work either.
1) SELECT {email} FROM {User AS user}
2) SELECT {p_originaluid} FROM {User AS user}
It's giving the same error for all the nonworking(wihth the different column names i.e p_originaluid) ones Exception message:
cannot search unknown field 'TableField(name='p_email',langPK='null',type=User)' within type User unless you disable checking, infoMap=TypeInfoMap for type = 8796093939794 code = User superType = 8796093841490 itemTable = users UPTable = usersup LTableName = userslp PropsTable = userprops core fields = owner = [owner,OwnerPkString,class de.hybris.platform.util.ItemPropertyValue] modifiedtime = [modifiedtime,modifiedTS,class java.util.Date] itemtype = [itemtype,TypePkString,class de.hybris.platform.util.ItemPropertyValue] creationtime = [creationtime,createdTS,class java.util.Date] pk = [pk,PK,class de.hybris.platform.core.PK] unlocalized fields = consentreference = [consentReference,p_consentreference, class java.lang.String] description = [description,p_description, class java.lang.String]
A bit of help will be great on the below questions:
1) Considering the above scenario why am I able to fetch all the columns?
2) While doing a flexible search I found "SELECT TypePkString FROM {User AS user}" query, my question is since TypePkString is a database column why is it used with SELECT without curly braces?
To answer your 1st question:
The way the type system works in SAP Commerce is. You have base item type and then you have drived item types. If you check core-items.xml Every type is derived from the generic item type directly or indirectly.
When you have any sub-item type derived from a parent type I.e Employee or B2BCustomer and you do not define a separate table ( tag ) for these separate types, the SAP Commerce uses a base table and add additional columns specific to those (Employee or B2BCustomer SAP) sub-item type.
This is why you may see many columns even for the specific type I.e B2BCustomer.
The best way to find the attributes added to specific subtypes is by looking into the back office type system.
In your case if you look into the type system by going into https://localhost:9002/backoffice/ -> Types -> User -> XML Representation and search for email, you may not find there
Now use the above steps and search for email under Type B2B Customer. You should be able to find it under the XML but when you look for email under core-items.xml file you might not find it there, that's because in the back office type system (for B2BCustomer) you will see it extended from (Extended tab) b2bcommerce. Now look for b2bcommerce-items.xml you should definitely see the item type for B2BCustomer and it should also have an attribute called email.
The reason for telling you above is so that you could know how and where to look.
When you use {} in your flexible search it uses the type system to look up and because of the same reason its unable to look it up email in User type is a part of B2BCustomer, not User, in your case:
select {email} from {B2BCustomer} should work.
For 2nd question:
As said before, Whenever you write {} in the flexible search, SAP Commerce looks into the type system and tries to resolve it however when you do not put curry braces it looked up DB columns for the given table like the below queries.
select p_email from {User}
select p_originaluid FROM {User}
Though p_email is not a part of User as told before you can still query it if you just try to fetch from the column directly same applies to the second query.
Hope this answers your question.
User item type hasn't got email property. Also it hasn't got originaluid. Check existing fields in backoffice type system or use hac to run queries without field names to get all existing fields.
Related
Whenever we save data to the database, there is always a corresponding ID which we use to fetch the data from that specific column.
sql_con.execute("SELECT FROM DBNAME WHERE ID = ?", id)
The above code only allows us to fetch data based from the ID. The problem is that the above code only accepts 1 supplied binding. In my database, I used sets of strings as the ID for each column, which means that the binding of my IDs are more than 1. And, those sets of strings have different bindings (or character count).
How do I modify the code in above, so I could input strings as my ID, preventing it from receiving the specific error:
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 8 supplied.
Thank you in advance. I use Python 3.xx and in-built module sqlite3. Database is in .db file format and is a disk-based database.
I found the answer for my own question, by asking someone else.
For you to resolve this problem with the bindings of the input, just simply convert the parameter into a tuple.
OLD CODE:
sql_con.execute("SELECT FROM DBNAME WHERE ID = ?", id)
INTO THIS...
NEW CODE:
sql_con.execute("SELECT * FROM DBNAME WHERE ID = ?", (id,))
Hope it helps.
I have created a non-persistent attribute in my WoActivity table named VDS_COMPLETE. it is a bool that get changed by a checkbox in one of my application.
I am trying to make a automatisation script in Python to change the status of every task a work order that have been check when I save the WorkOrder.
I don't know why it isn't working but I'm pretty sure I'm close to the answer...
Do you have an idea why it isn't working? I know that I have code in comments, I have done a few experimentations...
from psdi.mbo import MboConstants
from psdi.server import MXServer
mxServer = MXServer.getMXServer()
userInfo = mxServer.getUserInfo(user)
mboSet = mxServer.getMboSet("WORKORDER")
#where1 = "wonum = :wonum"
#mboSet .setWhere(where1)
#mboSet.reset()
workorderSet = mboSet.getMbo(0).getMboSet("WOACTIVITY", "STATUS NOT IN ('FERME' , 'ANNULE' , 'COMPLETE' , 'ATTDOC')")
#where2 = "STATUS NOT IN ('FERME' , 'ANNULE' , 'COMPLETE' , 'ATTDOC')"
#workorderSet.setWhere(where2)
if workorderSet.count() > 0:
for x in range(0,workorderSet.count()):
if workorderSet.getString("VDS_COMPLETE") == 1:
workorder = workorderSet.getMbo(x)
workorder.changeStatus("COMPLETE",MXServer.getMXServer().getDate(), u"Script d'automatisation", MboConstants.NOACCESSCHECK)
workorderSet.save()
workorderSet.close()
It looks like your two biggest mistakes here are 1. trying to get your boolean field (VDS_COMPLETE) off the set (meaning off of the collection of records, like the whole table) instead of off of the MBO (meaning an actual record, one entry in the table) and 2. getting your set of data fresh from the database (via that MXServer call) which means using the previously saved data instead of getting your data set from the screen where the pending changes have actually been made (and remember that non-persistent fields do not get saved to the database).
There are some other problems with this script too, like your use of "count()" in your for loop (or even more than once at all) which is an expensive operation, and the way you are currently (though this may be a result of your debugging) not filtering the work order set before grabbing the first work order (meaning you get a random work order from the table) and then doing a dynamic relationship off of that record (instead of using a normal relationship or skipping the relationship altogether and using just a "where" clause), even though that relationship likely already exists.
Here is a Stack Overflow describing in more detail about relationships and "where" clauses in Maximo: Describe relationship in maximo 7.5
This question also has some more information about getting data from the screen versus new from the database: Adding a new row to another table using java in Maximo
I would like to do some reporting on my CosmosDb
my Query is
Select Max(c.results.score) from c
That works but i want the id of the highest score then i get an exception
Select c.id, Max(c.results.score) from c
'c.id' is invalid in the select list because it is not contained in an
aggregate function
you can execute following query to archive what you're asking (thought it can be not very efficient in RU/execution time terms):
Select TOP 1 c.id, c.results.score from c ORDER BY c.results.score DESC
Group by isn't supported natively in Cosmos DB so there is no out of the box way to execute this query.
To implement this using the out of the box functionality you would need to create a new document type that contains the output of your aggregation e.g.
{
"id" : 1,
"highestScore" : 1000
}
You'd then need a process within your application to keep this up-to-date.
There is also documentdb-lumenize that would allow you to do this using stored procedures. I haven't used it myself but it may be worth looking into as an alternative to the above solution.
Link is:
https://github.com/lmaccherone/documentdb-lumenize
I can't wrap my head around how to have procedural a radioField, since I have to give each option a name.
In my case, I want to load the available options from a database and therefore I can't have them statically named. Has anybody an idea?
radioField handed [ (LeftHanded, LeftHandField, "Left")
, (RightHanded, RightHandField, "Right")
, (Ambidextrous, AmbiField, "Both")
]
I'm the author of Brick. For what it's worth, the Brick Users e-mail list is a good place to ask questions like this.
To your question, though: since the name type is under your control, you can give your name type a constructor that takes parameters to construct sufficiently unique name values that are relevant to the data for each radio button value. For example, if you load database data and each value of your radio button is associated with some numeric ID, you might just have a name type like:
-- The type of database record IDs
type ID = Int
data Name = ...
| RadioOption ID
I'm working on access restriction to res.partner.
Currently I have two questions:
1.Why does this code don't create new field to inherited model (first error was something like "unknown object _", now it's gone): (Now it works, first question is answered)
from odoo import models, fields
class partner(models.Model):
_inherit = 'res.partner'
privacy_visibility = fields.Selection([
('followers', _('On invitation only')),
('employees', _('Visible by all employees')),
#error was here. according to odoo documentation, here is a comma
#if you remove it, the code works: [![enter image description here][1]][1]([('',''),('',''),('','')])
],
string='Privacy', required=True,
default='employees',
help="Holds visibility of the partner that affects currently logged user:\n"
"- On invitation only: Employee may only see the followed partners\n"
"- Visible by all employees: Employee may see selected partner\n")
Later, when my restrictions would be applied, how to make selected users to access all pertners anyway? (my ideas - 1.to hide "privacy_visibility" field to be visible in developer mode only, as it made for project's "sub-task project". 2.to create a new group, but I have no idea how to use access groups with row-level access), which way wold you recommend to go?
First Question Ans:
The Selection field syntax is not correct please follow this syntax
Example:
gender = fields.Selection([('male', 'Male'), ('female', 'Female'), ('any', 'Any')], string='Gender')
You are calling the translate object (the underscore "_") to translate your selection values, but you did not import it.
Change:
from odoo import models, fields
To:
from odoo import models, fields, _