XPages - save date only in Date field

前端 未结 2 1261
死守一世寂寞
死守一世寂寞 2021-01-20 02:58

I\'m using an Edit Box control to display a date field. When the XPage is saved, I would like to save the date only (now both date and time are being saved). Is there any wa

相关标签:
2条回答
  • 2021-01-20 03:15

    This code worked for me:

        <xp:this.postSaveDocument><![CDATA[#{javascript:
            var dt:DateTime = document1.getItemValueDateTime("dateReparatur");
            dt.setAnyTime();
            currentDocument.getDocument(true).replaceItemValue("dateReparatur", dt); 
            currentDocument.getDocument(true).save()
        }]]></xp:this.postSaveDocument>
    

    enter image description here

    It does work at postSaveDocument event only. If you put the same code into querySaveDocument event (without document save() line of course) the date field gets polluted with time after event during saving.

    An alternative is to execute computeWithForm at querySaveDocument event:

    <xp:this.querySaveDocument><![CDATA[#{javascript:
        document1.getDocument(true).computeWithForm(true, true)
    }]]></xp:this.querySaveDocument>
    

    You'd have to add an Input Translation formula to date field(s) in your form:

    @Date(@ThisValue)
    

    computeWithForm has a poor performance and causes sometimes side effects on field values though but might be a good solution especially if you have a lot of such date-only-fields.

    0 讨论(0)
  • 2021-01-20 03:24

    getDateOnly() returns a string. Try this:

    dt.setAnyTime();
    currentDocument.replaceItemValue("dateReparatur", dt);
    

    Or you may have to get the Document:

    currentDocument.getDocument(true).replaceItemValue("dateReparatur", dt);
    
    0 讨论(0)
提交回复
热议问题