Keywords
I'm trying to add keywords in python but it doesn't seem to work. I think I am doing something wrong. Here is my code:
from com.infinitekind.moneydance.model import *
import java.util.ArrayList # Keywords are in an ArrayList
import sys
txnset = moneydance.getCurrentAccountBook().getTransactionSet() # all transactions
permittedDescriptions = ["DEFT - KPR"] # permitted descriptions which are not subject to case change
txnsParents = filter(lambda x:x.class.name == "ParentTxn" and x.getDescription() <> "" and len(x.getDescription()) > 5 and x.getDescription() not in permittedDescriptions and x.getDescription().upper()==x.getDescription(), txnset )
for txn in txnsParents:
keywords = txn.getKeywords()
print 'old keywords:', txn.getKeywords()
if not keywords.contains(str("caseChanged")):
print "not contains"
keywords.add (str("caseChanged"))
txn.setKeywords(keywords)
txn.getParentTxn().syncItem()
When I run this the console gives messages like:
old keywords: [caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged, caseChanged]
but the Find & Replace extension shows only one "caseChanged" tag, not multiple copies. However, when I quit md and then reopen it, no tens have a "caseChanged" tag. What am I doing wrong?Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Sean Reilly on 23 Mar, 2018 03:38 PM
Hi David,
My best guess here is that the keywords.contains(str("caseChanged")) is returning false because the python string "caseChanged" is seen as different to the java string. Can you try it with something like `if not keywords.contains(java.lang.String("caseChanged"))` or even `if not keywords.contains("caseChanged")` to see if you get different results?
Thanks,
Sean
2 Posted by davidcullen on 26 Mar, 2018 01:25 PM
It seem to work (haven't finished extensive testing) with java.lang.String. Thanks for your help.
System closed this discussion on 25 Jun, 2018 01:30 PM.