Change the state of a checkbox in the backend

231 views Asked by At

In ssjs I try to change the state of a checkbox. I tried :

doc.replaceItemValue( 'picWeb', "true" );

which doesn't seem to change anything (checkbox doesn't change to checked)

I also tried :

doc.replaceItemValue( 'picWeb', true );

which throws an error

( [TypeError] Exception occurred calling method NotesDocument.replaceItemValue(string, boolean) null)

If I understand it well :
you can't change a checkbox (boolean) with replaceItemValue, but how do I change it then ? Is it possible with ssjs or java or ...

1

There are 1 answers

0
Knut Herrmann On BEST ANSWER

Define in checkbox which string relates to checked value and which to unchecked value with the properties checkedValue and uncheckedValue:

enter image description here

    <xp:checkBox 
        ... 
        uncheckedValue="false" 
        checkedValue="true">
    </xp:checkBox>

You can set the value then with

document1.replaceItemValue("picWeb", "true") 

This is a complete example to demonstrate how to set a checkbox value in SSJS:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:this.data>
        <xp:dominoDocument var="document1" formName="Test" />
    </xp:this.data>
    <xp:checkBox text="picWeb" id="checkBox1" 
        value="#{document1.picWeb}" 
        uncheckedValue="false" 
        checkedValue="true">
    </xp:checkBox>
    <xp:button value="True" id="button2">
        <xp:eventHandler event="onclick" submit="false" 
            refreshMode="partial" refreshId="checkBox1">
            <xp:this.action><![CDATA[#{javascript:
                document1.replaceItemValue("picWeb", "true")
            }]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>
    <xp:button value="False" id="button3">
        <xp:eventHandler event="onclick" submit="false" 
            refreshMode="partial" refreshId="checkBox1">
            <xp:this.action><![CDATA[#{javascript:
                document1.replaceItemValue("picWeb", "false")
            }]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>
    <xp:button value="Submit" id="button1">
        <xp:eventHandler event="onclick" submit="true" 
            refreshMode="complete" immediate="false" save="true">
        </xp:eventHandler>
    </xp:button>
</xp:view>

The value is set in document as string

enter image description here