Open beblank opened 10 years ago
I am not sure https://github.com/plomino/Plomino/issues/456 can be used in your case. What do you want to do exactly ? If you want to forbid that any new document is created using a given form if there is already one document existing, that's easy, you add this in your onBeforeCreateDocument event:
db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'my_singleton_form'})
if len(existingdocs) > 0:
return "Sorry, you cannot create another doc with this form."
what i need to do is if there's an existing document then show existing document edit mode
thanks
tried that and nothing happened no notification and still creating new document
ok, well then the best approach is to create an action or an agent that will check if the doc exists and then redirect either to the /OpenForm url or to the /EditDocument url
sorry it works i still using admin when tried it i change some script
db = context.getParentDatabase() existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1'}) if len(existingdocs) > 0: olddoc = existingdocs[0].getObject() return open_url(context.REQUEST.response.redirect(olddoc.doc_url()+'/OpenDocument'), false)
but it show error how to fix it
thanks
Don't do open_url
. You want to set the REDIRECT key on the request, and then just return the URL as a string. The agent will do the redirect for you:
context.REQUEST.set('REDIRECT', 'True')
return olddoc.doc_url()+'/OpenDocument'
so the script would be just like this?
db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1'})
if len(existingdocs) > 0:
olddoc = existingdocs[0].getObject()
context.REQUEST.set('REDIRECT', 'True')
return olddoc.doc_url()+'/OpenDocument'
it won't redirect the url just show as a string
Validation failed return url go back button
why not using open_url
?
now the problem is every user can't add another forms data because it ends up shows old data so i have and idea to check the user. i created a user field which is computed to currentUser
db = context.getParentDatabase()
current_user_id = db.getCurrentUser().id
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1'})
length = len(existingdocs)
for i in existingdocs(0,length)
if (forms.user[i] == current_user_id)
olddoc = existingdocs[i].getObject()
context.REQUEST.set('REDIRECT', 'True')
return olddoc.doc_url()+'/OpenDocument'
how to access all the user field array?
thanks
The user id is stored in the Plomino_Authors field (which is a list), so the right way to do it is:
db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1', 'Plomino_Authors': [db.getCurrentUser().getMemberid()]})
if len(existingdocs) > 0:
blabla
db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1', 'Plomino_Authors': [db.getCurrentUser().getMemberid()]})
if len(existingdocs) > 0:
return 'test'
formula error and noting happend
how to to this the other way? how can i search a value from field of form? it should be easy to do this when i get the value
ok i get it working thanks
db = context.getParentDatabase() currentUser = db.getCurrentUser().getMemberid() existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1', 'UserField': currentUser}) if len(existingdocs) > 0: return 'test'
How to make the forms input just 1 time if already filled then show the filled forms i know theres a onOpenDocument event i tried some solution from https://github.com/plomino/Plomino/issues/456
but the /EditDocument shows error
thanks