Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

plomino form onsave get current field value

Help
J.D.
2011-06-23
2013-04-25
  • J.D.
    J.D.
    2011-06-23

    Hello!
    First off im a programmer with LAMP  background and ive been working with plomino for about 7 months, so im sure im not using plomino correctly.

    Ive been working on trying to get a simple field lookup, but ive been having alot of issues.
    I have been able to get everything to work except getting a fields value (from another db) on the current form.

    So in my form that contains a bunch of fields i have one field that contains a selection list from another DB that has 2 records (lets say ItemName, and ItemDescription).
    When the user saves the form, i need to get the value from the dropdown list (lets say ItemName) and replace it in the script below.

    #Here is what i have so far..
    #In the forms onSave event i....
    #First get the db.
    thedb=plominoDocument.restrictedTraverse('ourSite/somefolder/myTests/listOfParts/')
    #then i get the view
    listOfPartsView=thedb.getView('all')
    #once i have the view i can get the views values
    allViewValues=listOfPartsView.getAllDocuments()
    #this is what i need to replace, it should get the value from the selection list in the current form ..
    lookup = 'one of the values"
    #init 
    ItemDescriptionsValue = 0
    #loop for all rows in ListOfParts
    for row in allViewValues:
      #finding the lookup record (ItemName) from listOfParts
      if lookup == row.ItemName:
        #get ItemDescription from listOfParts
        ItemDescriptionsValue = row.ItemDescription
    #set the current form field to the value form ItemDescription (of the other db)
    plominoDocument.setItem('formField2',ItemDescriptionsValue)
    

    I have made formField2 hidden in edit mode… im just trying to make the user not have to enter the description when we have it in another form.
    Thank you for your time.
    J

     
  • Eric Brehault
    Eric Brehault
    2011-07-01

    Hello,

    First thing:
    allViewValues=listOfPartsView.getAllDocuments()
    it returns not actual PlominoDocuments but search resulst (ZCatalog brains), so they do not behave as PlominoDocument
    if ItemName and ItemDescription are indexed, row.ItemDescription and row.ItemName will work (becaus ethose values will be part of the index)
    but if they are not, you will get an AttributeError
    if so, do the following:
    doc = row.getObject()
    doc.ItemDescription

    Second thing:
    there is easier wat to do it:
    sort your 'all' view by 'ItemName' (make it a column first)
    then:
    matching_docs =

    it avoids to make a loop to test every documents

    Eric