plomino / Plomino

Powerful and flexible web-based application builder
33 stars 37 forks source link

Changing dynamically document title (and Document id formula) #783

Closed ermancio closed 7 years ago

ermancio commented 7 years ago

Hello everybody. I set the document title formula to compute the document title. I need to change it when an event occurs. Is it possible? The problem arises because I set one calculated field (ID_state) which must change when it is saved (onsave event). For example: in document Title formula I have:

"Document" + ' ' + str(plominoDocument.ID_state)

but onsave document I have

_if plominoContext.getItem('State') == 'Open': plominoContext.setItem('ID_state', 'O')

if plominoContext.getItem('State') == 'Archived': plominoContext.setItem('ID_state', 'F')

if plominoContext.getItem('State') == 'Null': plominoContext.setItem('IDstate', 'N')

Thank you

ermancio commented 7 years ago

I'm using Plomino 1.15.....

ebrehault commented 7 years ago

It should work the way it is, but I guess this will a better Title formula:

if plominoContext.getItem('State') == 'Open':
    return"Document O"
if plominoContext.getItem('State') == 'Archived':
    return"Document F"
if plominoContext.getItem('State') == 'Null':
    return"Document N"
ermancio commented 7 years ago

Great! It works perfectly. Thank you

ermancio commented 7 years ago

One more question: I need to define the ID Formula only for new document and leave the assigned ID for edited document.

I try to do in this way:

if plominoContext.isNewDocument(): if plominoContext.getItem('State') == 'Open': return"Document O" if plominoContext.getItem('State') == 'Archived': return"Document F" if plominoContext.getItem('State') == 'Null': return"Document N"

and that's fine. But I miss the "else" condition. How can I leave the id as already defined?

Thank you

ebrehault commented 7 years ago

The document ID formula is executed only once at creation time. The id is not meant to change at anytime after that.