set up a value from a javascript field to a boolean field

122 views
Skip to first unread message

tzarinak...@gmail.com

unread,
Apr 20, 2019, 1:23:30 PM4/20/19
to mementodatabase
Hi everybody.

I'm struggling with a javascript fiel trying to do an apparently easy thing. I need to change the value of a boolean field from a javascript field both in the same entry. After reading the wiki examples I ended with the next script:

field("valor del campo ESTADO: resuelto", false)
if (field("ESTADO:") == "RESUELTO") {
true
field("valor del campo ESTADO: resuelto", true)
}

First I set the "valor del campo ESTADO: resuelto" to false although I know is not necessary because I set it "unchecked" as defoult when I set up that field, but.....
I set the "true" after the "IF" condition just to test if the condition works OK. And is working because when I change the value of "ESTADO" the javascript field value changes to "true" or "false" properly.
But the value of "valor del campo ESTADO: resuelto" always remains "false" or unchecked.
I know there are differences between Javascript fields and trigger scripst. I tried using "set(field("ESTADO:")" but gave me error.

Hope anyone can throw some light on this.
As you can imagin I have no idea of javascript. I'm just trying to set up my libraries using information from the wiki examples and the posts from the forum wich I found very usefull.

Thanks in advance for the help.
Introducir código aquí...


Bill Crews

unread,
Apr 20, 2019, 1:55:38 PM4/20/19
to tzarinak...@gmail.com, mementodatabase
Here's a script that should work for you ...

if (field("ESTADO:") == "RESUELTO")
   True;
else
   False;

The field() function accepts only one argument, not two and does nothing to the database; it merely returns the current entry's value of the field whose name is ESTADO:. Note that, the way you coded it, the colon is part of the field name; if that's not how you defined it, remove the colon. I'm confused by and therefore ignoring the "valor del campo ESTADO: resuelto" on the first & fourth lines of your script. I think the 4 lines above will set your Boolean field based on the value of the other field.

tzarinak...@gmail.com

unread,
Apr 21, 2019, 4:08:26 PM4/21/19
to mementodatabase
Thankyou very much Bill.
I think I didn't explain myself very well. Is my foult. Please let me explain it better:

I have a library with some fileds. Among them I have one call "ESTADO:"(with the colon). This is a single choice list field with two elements("PENDIENTE" and "RESUELTO"). This field has two dependencies one for visibility of the field and the other for content of the elements: when field "valor del campo ESTADO: resuelto" is true then element "PENDIENTE" is not showing.
In this same library I have a page call "CÁLCULOS". In this page I have two fields that I have set up with dependencies to be always invisible.

One is "valor del campo ESTADO: resuelto" and is a boolean field set up with format: On label: true, Off label: false. And defaoult value: No, which means that is not marked. This is the field I want to change the value with the javascript field.

The secondone is the field "cálculo ESTADO". Is a javascript field and is the one with the script I want to use to change the value of the "valor del campo ESTADO: resuelto" field. That means that I don't bother the result of this field because the utility of this field is only to change the value of the "valor del campo ESTADO: resuelto" field.

All this trouble is just because I want that once I select the element "RESUELTO" in the "ESTADO:" field I want not to show the element "PENDIENTE" anymore in case you try to edit the field again in the future.

Perhaps there is an easy way to achieve this action, but I don't know other way.
Perhaps what I'm trying to do is not possible with a javascript field and/or a boolean field.
The truth is that when I look in the entry the field "valor del campo ESTADO: resuelto"(after removing the dependencies to see the field) it is always unmarked whatever the value of "ESTADO:" is.

Sorry for the long post. Hope you or anyone can tell me something about all this.

Thanks.

Bill Crews

unread,
Apr 22, 2019, 2:51:52 AM4/22/19
to tzarinak...@gmail.com, mementodatabase
Keep in mind that this is a user forum, and I am a user trying to help.


This is a single choice list field with two elements("PENDIENTE" and "RESUELTO"). This field

Both the desktop and mobile apps and the wiki refer to the "elements" of list fields as well as radio buttons & checkboxes field as "items". This time, I understood; in the past, I have failed to understand and so didn't respond to many messages, when terms are used that we don't know about or understand. Some of us understand databases pretty well; some don't understand them at all. So, PLEASE use the MEMENTO terms, so we're all talking about the same things and understanding each other.

To the gentleman (IIRC) called Katerina: The following paragraph applies to you in a very SMALL way, but it applies to EVERYONE in this forum, some in a much bigger way ...

I've asked MANY TIMES over the years in this forum for senders to type their messages in their NATIVE language or in any language they COMPLETELY know & understand, but VERY FEW do this, though it would not only be EASIER for the senders, but would also keep recipients from MISUNDERSTANDING messages; maybe all new forum members are new to the forum? Sigh. Web translator apps nowadays work MUCH BETTER than people who don't know the language as well as they would like. If you need to practice, please do it somewhere else.

elements: when field "valor del campo ESTADO: resuelto" is true then element "PENDIENTE" is not showing.
In this same library I have a page call "CÁLCULOS". In this page I have two fields that I have set up with dependencies to be always invisible.

I used dependencies a few times years ago; I barely remember about them now, AND the way they work could have changed, and I wouldn't know it. If I responded to this, I'd likely just mislead you, so I won't. Instead, I HOPE SOMEONE ELSE CAN HELP YOU, SINCE I CAN'T.

One is "valor del campo ESTADO: resuelto" and is a boolean field set up with format: On label: true, Off label: false. And defaoult value: No, which means that is not marked. This is the field I want to change the value with the javascript field.

The secondone is the field "cálculo ESTADO". Is a javascript field and is the one with the script I want to use to change the value of the "valor del campo ESTADO: resuelto" field. That means that I don't bother the result of this field because the utility of this field is only to change the value of the "valor del campo ESTADO: resuelto" field.

If I understand you correctly, you want the value of the Boolean field A to change depending on the value of the single-choice list field B? That is simple and IIRC, the wiki either explains this directly or comes close and contains links for learning JavaScript.

Recreate Boolean field A as a JavaScript field using the following script, which is almost exactly like the script I sent earlier.

if (field("B") == "RESUELTO")
   True;
else
   False;

Of course, you can name B anything you like.

Please forgive me; I need to make the following very clear ...

IT WAS YOUR UNDERSTANDING OF JAVASCRIPT, MEMENTO, OR BOTH AND NOT MY SCRIPT THAT WAS IN ERROR. Please try harder.

I believe I told you previously (as does the wiki) that JAVASCRIPT FIELDS CANNOT AFFECT THE VALUE OF OTHER FIELDS IN ANY LIBRARY. NEVER. EVER. The ONLY reason to use a JavaScript field in Memento is TO GET A CALCULATED VALUE, so if you need something else, look elsewhere. A JavaScript field can return a value of any type (Text, Integer, etc). In this case, it will return a Boolean value.


tzarinak...@gmail.com

unread,
Apr 22, 2019, 5:38:42 PM4/22/19
to mementodatabase
Thanyou very much, Bill, for your answer. Really you are doing a great job in the forum. All my respect to people like you that spend his time and energy to help people like me in all forums.

The problem was that I was trying to do something that is not possible. I was trying to affect the value of other field from a javascript field. Thanks to you, now I know it is not possible.
Before asking in the forum I read the wiki and search in the forum for this information but didn't find it, which doesn't mean it is not there. Is just I didn't find it.
I will try other way.

I'm absolutely agree with you about using the Memento terms. I read some posts of you explaining this point and when I have read other post where people didn't use this terms I didn't like it. So is my foult and I need to be more careful in the future. I just did a fast translation from the "items" tab from my language.

I needed a boolean field because, as far as I know(and I knew very little), to set up dependencies you need to do it based on the choices of a field with choices(Checkbox (Boolean), Radio buttons, Checkboxes, Single-choice list, Multiple-choice list) and is not possible to set up dependencies based on the result of a javascrip field.


Of course, Bill, is my understandig of Javascript and Memento behind all my errors. If there is somenthing in my last post that has led you to understand that I was saying your script has an error I apologise publicly. As I told you before I respect you a lot for your knoledge and your work here in the forum.
As you pointed my english is not very gut(and I'm agree) and perhaps I didn't use it properly to express myself.


Thanks againg, Bill, for your help.

Bill Crews

unread,
Apr 23, 2019, 4:09:28 AM4/23/19
to tzarinak...@gmail.com, mementodatabase
I see your point and agree that it isn't possible right now in Memento, but only because the user dependency edit card doesn't allow the JavaScript field type; functionally, I know of no reason a JavaScript couldn't work like a Boolean field, a radio buttons field, or a checkboxes field; because it can be used in all these ways, changing the user interface for this would be a bit tricky, but I think it's possible, and I've suggested this enhancement to the developer. If doing this enhancement turns out to be as simple as I envision, maybe it can be added to Memento soon. I never know for sure.

I appreciate terminology and language challenges like yours in this case; I merely wanted not only you, but all forum members to hear the benefits of doing these things, and saying it in response to your message seemed like an appropriate way to do it. I hope you don't feel disparaged; you shouldn't, in my opinion.

tzarinak...@gmail.com

unread,
Apr 23, 2019, 4:03:01 PM4/23/19
to mementodatabase
Thanks, Bill, for the answer. Of course I don't feel disparaged. I feel fortunate to have the opportunity to learn thanks to people like you, here and in another places.
And in the process I asume I will make lot of mistakes not only with Memento or javascript but also in the forums(which are also something relatively new for me).

With a new aproach to the problem I have arrive to a very close performace of what I was looking for. I will explain it in case is usefull for anyone.

I recall the matter:

I have a single-choice list field called "ESTADO:" with two items:("PENDIENTE" and "RESUELTO"). Item "PENDIENTE" is set as default.
I want that once I select "RESUELTO" item the "PENDIENTE" item does not show anymore to avoid the possibility to select it.

Finally, and thanks to Bill's help, I solved as follow:

I created a new page called "CÁLCULOS". In this page I created a boolean field called "valor del campo ESTADO: resuelto"(yes, is more a description than a name...) with format: On label: true. Off label: false. And set "false" as default. This field has no visual utility, so I set up a dependency in this field(dependent) to be always invisible, using as master field any other field of the library with choices.
Return to the MAIN page, I set up a dependency in the field "ESTADO:"(dependent) using field "valor del campo ESTADO: resuelto" of the "CÁLCULOS" page as master.
The depencency is a content dependency and is set up as follow: for the master field "valor del campo ESTADO: resuelto" value "true", the item "PENDIENTE" is no more available for selection. For the master field "valor del campo ESTADO: resuelto" value "false", both "PENDIENTE" and "RESUELTO" items are available for selection.

Then I create two triggers in this library containing the same script for different events:

one for event: updating an entry, phase: opening an entry edit card. No need of security permissions.
other for event: opening an etry view card, phase: before window display. No need of security permissions.

The script is:

var e = entry();
if (e.field("ESTADO:") == "RESUELTO")
e.set("valor del campo ESTADO: resuelto", true);

That's it.

There is only one problem. I set up the single-choice list field "ESTADO" to be editable in the entry list view. If I change the value of the "ESTADO" field in the entry list view tapping on its icon from "PENDIENTE" item to "RESUELTO" item and I tap againg the icon to it keeps showing the two items. I need to enter to entry view card or entry edit card to make the trigger run.

If anyone knows other way to do this or a way to improve this way I will be very grateful to know.

Sorry for so long post.

Bill Crews

unread,
Apr 25, 2019, 4:55:59 AM4/25/19
to tzarinak...@gmail.com, mementodatabase
I don't fully follow all this, but I do know that there are cases in Memento where an entry can be updated without running Updating triggers. The only one I know of is when a choice field is specified to be displayed in the list. Changing a Boolean or choice list field value from the list screen will not cause any triggers to run (boo). The developer knows about this; maybe it'll be fixed some day (shrug). Maybe you have identified another such circumstance.

By the way, it's not important, but I don't know why you need a dependency for your "valor" field.
Reply all
Reply to author
Forward
0 new messages