DominoV9->DominoV12 バージョンアップでXpagesエラーが発生した件
こんにちは。Xpages担当の米原です。 本日はXpages...
When a form has the fields with “date only” or “time only”, then the stored data format are different between Notes Client and XPages.
For example, I prepared the field with “date only” named “Date” as following (sorry, screenshots are all Japanese) :
And also field with “time only” named “Time”:
Now I saved a new document with this form from Notes Client (9.0.1 FP3), then I got following fields’ data.
As you see, “Date” field has “2015/03/02″, and Time field has”14:35:00”
As the next, I created the simple XPage to save a new document with same form and fields so that I can compare the data between Notes Client and XPages.
Below is the source code for Date field and Time field in XPages.
Date Field
<xp:inputText value="#{document1.Date}" id="date1"> <xp:dateTimeHelper id="dateTimeHelper1"></xp:dateTimeHelper> <xp:this.converter> <xp:convertDateTime type="date" dateStyle="short"> </xp:convertDateTime> </xp:this.converter> </xp:inputText>
Time Field
<xp:inputText id="time1" value="#{document1.Time}"> <xp:dateTimeHelper id="dateTimeHelper2"></xp:dateTimeHelper> <xp:this.converter> <xp:convertDateTime type="time" timeStyle="short" timeZone="Japan"> </xp:convertDateTime> </xp:this.converter> </xp:inputText>
Each inputText specify date, time to the Type attribute of convertDateTime.
After saving a new document from this XPage, below is the screenshot of stored field data:
So both of fields have “yyyy/MM/dd hh:mm:dd ZZ” format.
I just don’t post this blog to argue which format is proper way and why XPages behaves differently.
In the real world, I think you or your customers already have the NSF apps and you may want to improve them as the web application by XPages. In that case, especially you decide to keep using the NSF from both Notes Client and XPages, then I recommend to adjust the field format to Notes Client one instead of XPages one so that all existing documents are supported both Notes Client and XPages without changing data.
Maybe there are a lot of way to achieve what I want below. But one of easy way is using NotesDateTime class of SSJS.
<xp:this.data> <xp:dominoDocument var="document1" formName="Form" computeWithForm="both"> <xp:this.postSaveDocument><![CDATA[#{javascript: var dt:NotesDateTime = document1.getItemValueDateTime("Date"); dt.setAnyTime(); var tm:NotesDateTime = document1.getItemValueDateTime("Time"); tm.setAnyDate(); var notesDoc:NotesDocument = document1.getDocument(); notesDoc.replaceItemValue("Date", dt); notesDoc.replaceItemValue("Time", tm); notesDoc.save(); dt.recycle(); tm.recycle(); notesDoc.recycle(); }]]></xp:this.postSaveDocument> </xp:dominoDocument> </xp:this.data>
The SSJS above converts the DateTime field format by using setAnyTime()、setAnyDate() in PostSaveDocument event after saving the XSP document .
Thanks. This is exactly what I needed.
お世話になります。年月日のみを文書格納したくこちらへたどり着きましたが、setAnyTime()を使用しても、どうしても日付のみとならず時刻が付与された形式にて作成されてしまいます。なにか見落としがありますでしょうか。
xp:this.beforeRenderResponseにて、
var tempRenewalYear = (document1.getItemValueString(“RenewalYear”));
var tempRenewalMonth=( document1.getItemValueString(“RenewalMonth”));
var tempRenewalDay = (document1.getItemValueString(“RenewalDay”));
var tempRenewal = tempRenewalYear + “/” + tempRenewalMonth + “/” + tempRenewalDay;
var ndt:NotesDateTime = session.createDateTime(tempRenewal + ” 00:00:00″);
ndt.setAnyTime();
document1.replaceItemValue(“Renewal”, ndt);
document1つまり、NotesXspDocumentオブジェクトに対してreplaceItemValue() をしているようです。
ブログ内のサンプルにあるように
var notesDoc:NotesDocument = document1.getDocument();
としてNotesDocumentオブジェクトに対してreplaceItemValue()するようにしてみてはどうでしょうか?
(ソースだけを見て返事しているので検討ちがいかもしれません、その時はまたここに書き込んでください)
早速のアドバイスをありがとうございます。
結果、期待する動作を確認できました(_ _)謝々
頂戴したアドバイスと下記を組み合わせることで
document1の“Renewal”へ年月日のみ(時刻なし)を
格納することができました。
おかげさまで抱える課題の一つが解決できました。
今後ともよろしくお願いいたします。
※サンプルコードより
13行目> var notesDoc:NotesDocument = document1.getDocument(true);
16行目> //notesDoc.save(); ←後続でdocument1.save()を実行