1
votes

I'm working with the XPages querysavedocument event for the first time and am trying to stop the XPage from being saved. I've tried

return false;

but this does not stop the document from being saved. What is the correct syntax to stop the XPage from being saved?

The code which saves the document is:

<xp:this.action>
<xp:saveDocument var="document1"></xp:saveDocument>
</xp:this.action>

This is the same as in Knut's answer below. The code which I have in the querySaveDocument is

var choice:boolean = false;

for (var k = 1; k < 7; k++) {
    choice = false;
    sectionname = "C1B"+k;
    for (var n = 1; n < 7; n++) {
        fieldname = "C1B"+k+"_R"+n;

        if (getComponent(fieldname).getValue() != ""){
            choice = true; 
            break;};
    }

    if (choice == false){
        viewScope.put("EmptyRadioField",sectionname);
        var comp = getComponent("RadioButtonValidationDialog");
        comp.show();
        return false;
    }
}

The dialog box is shown correctly when choice == false but the XPage is saved nonetheless.

I have solved my problem by moving the validation to csjs:

for (var k = 1; k < 7; k++) {

choice = false;
sectionname = "C1B"+k;

for (var n = 1; n < 7; n++) {
fieldname = "C1B"+k+"_R"+n;

var id = "view:_id1:_id2:_id3:"+fieldname;
fieldvalue = dijit.byId(id).getValue();

if (fieldvalue != false){
choice = true; 
break;};

}

if (choice == false){

sectionid = "view:_id1:_id2:_id3:lbl"+sectionname;
sectionvalue = dojo.byId(sectionid).innerHTML;
alert("Please enter a value for " + sectionvalue);
return false;

}
}   

This works well, despite a lot of trying I just couldn't get it working in SSJS.

1
So you are looking for XPages equivalent of Continue = False in LotusScript?Naveen
yes, that is what I wantuser1358852
Did you put the } in break line on purpose? -I guess, last if should be inside of both for loops?Knut Herrmann
Yes, the code is as I want it. Once an empty field is found, the dialog is displayed. This however seems to happen after the document has already been saved. The choice == false condition is triggered outside the n loop but inside the k loop.user1358852
If I replace the above code with simply "return = false;", the document is nonetheless saved.user1358852

1 Answers

1
votes

return false; is right.

Maybe, the event querySaveDocument does not get executed at all. That happens e.g. if you save the document in SSJS with document1.save().

You have to have a save action like

  <xp:this.action>
     <xp:saveDocument var="document1"></xp:saveDocument>
  </xp:this.action>

or to use

<xp:eventHandler
    event="onclick"
    submit="true"
    refreshMode="complete"
    immediate="false"
    save="true">
</xp:eventHandler>