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 way of doing this?
Here is my code:
<xp:inputText id="dateReparatur" value="#{document1.dateReparatur}">
<xp:this.converter>
<xp:convertDateTime type="date" dateStyle="long">
</xp:convertDateTime>
</xp:this.converter>
<xp:dateTimeHelper></xp:dateTimeHelper>
</xp:inputText></xp:td>
UPDATE: I have now implemented the following code:
var dt = currentDocument.getItemValueDateTime("dateReparatur");
var dateonly = dt.getDateOnly();
currentDocument.replaceItemValue("dateReparatur",dateonly);
This gives me the date only, however in Notes the field type is now text rather than Date/Time, which is what I was hoping for.
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>
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.
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);
Related
I am having a hard time getting a statement to render in SS2, I had found an answer is SS1 and hadn't used it sometime back but it doesn't seem to work in ss2. I am using the SS2 render.statement method but I am getting an "error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["renderStatement(N/render.js)" I am unclear as to what some of the arguments actually are. the entityid I think is the customer id, the printMode is the pdf enum, the formId I have no idea, it says it wants a number but I don't see internal ids next to the forms in the list like other objects in NetSuite, I have the InternalIds on. StartDate is a date before you want to start pulling in transactions from? Statement date? Todays Date? OpentransactionOnly true. Any help with this is appreciated.
thanks
Many of the parameters in this API call mimic the UI options on the 'Print Individual Statement' page. I've copied some of the field level help there to help explain each setting.
entityId - internal ID of the customer. NOTE: I have had errors in the past which were solved by using parseInt(customer).
printMode - the print mode to render this statement in (eitherrender.PrintMode.HTML or render.PrintMode.PDF)
formId - internal ID of the form to use to print the statement. Leave this option off to use the default statement form.
startDate - If you choose to enter a date, this is the date of the oldest transaction that appears on the statement. If you choose to note enter a date, all transactions in the customer's history appear on the statement.
statementDate - Statement date. The date in this field is the date used to calculate aging and the date that appears on the statement form.
openTransactionsOnly - Select this option to include only open transactions on statements. If you have entered a start date, open transactions from that start date appear. If you have not entered a start date, all open transactions appear. The Show Only Open Transaction option is most useful for statements printed as of your current today date. If you select Show Only Open Transactions and are using a date other that today’s date, you may have balance discrepancies.
Here is an code snippet. It uses the moment.js for calculating the dates of the first and last day of the previous month.
var startDate = format.format({
value: moment().subtract(1, 'months').startOf('month').toDate(),
type: format.Type.DATE
});
var statementDate = format.format({
value: moment().subtract(1, 'months').endOf('month').toDate(),
type: format.Type.DATE
});
var statement = render.statement({
entityId: parseInt(customer),
printMode: render.PrintMode.PDF,
startDate: startDate,
statementDate: statementDate
});
In the past, I've added multi-value text data to a field putting the values into a simple JavaScript array. For example:
doc.replaceItemValue('AlwaysAccess', ["John Doe","Bob Smith"]);
Any recommendations on how to store a series of DATES in a multi-value, Time/Date field in a Notes document?
TL;DR: The concept should be almost identical to a multi-value Field of Strings, your Date(/Time) values need to be valid NotesDateTime values properly stored.
A Notes field can have multiple Date/Time values; you can see this in the Form, selecting a field of type Date/Time and checking "Allow multiple values".
You can also see that a multi-value of from the replaceItemValue page of the Domino Designer Knowledge Center.
To accomplish the same with the NotesDominoAPI (in SSJS), we'll need to:
get a handle on the NotesItem (the field, which I'll create)
create our values to put in the field (I'll create a couple using session.createDateTime)
add these values to a java.util.Vector, which will be interpreted as multi-value (you should also be able to use the SSJS Array, if you prefer)
set the values to the field
Sample code (I just ran it in the onClick event of an xp:button):
//create a new doc
var tmpDoc:NotesDocument = database.createDocument();
//give it a Form
tmpDoc.replaceItemValue("Form","MultiDateFieldForm");
//create a NotesItem
var itm:NotesItem = tmpDoc.replaceItemValue("DateFieldName",new java.util.Vector());
//create the Vector, our multi-value container
var vec:java.util.Vector = new java.util.Vector();
//create a couple NotesDateTime values to store
var first = session.createDateTime(new Date());
vec.add(first);
var second = session.createDateTime("Tomorrow");
vec.add(second);
//save the values to the item
itm.setValues(vec);
//save
tmpDoc.save();
//recycle!
first.recycle();
second.recylce();
itm.recycle();
tmpDoc.recylce();
[Edit]
As Frantisek Kossuth points out in the comments, be sure to recycle your NotesDomino API objects (especially the Date/Time ones). I've updated the code to reflect this.
[/Edit]
Checking a Form-based View after running, I'm giving this (field properties reflect the multi-value field of Date/Time values; two shots as it ran out of the box).
Essentially, I found that I needed to create a vector to store the list of dates, and populate it with NotesDateTime objects.
var vRepeatDates:java.util.Vector = new java.util.Vector();
In my case, I needed to increment the dates x amount of times. So, I used a for loop to add the NotesDateTime elements to the vector (while using .adjustDay(1) to increment the dates)
And finally store the vector in a field using replaceItemValue()
doc.replaceItemValue("RepeatInstanceDates",vRepeatDates);
I followed How do you copy a datetime field from the current document to a new document and I try something like this:
Cdoc.save();
Pdoc.copyItem(Cdoc.getDocument().getFirstItem("mytest1"));
getComponent('exampleDialog').show()
But I get a handling error message.
Thanks for your time!
Assuming Cdoc and Pdoc are defined as xp:dominoDocument data sources then you have to change your code to:
Cdoc.save();
Pdoc.getDocument().copyItem(Cdoc.getDocument().getFirstItem("mytest1"));
getComponent('exampleDialog').show()
So, you only need to add .getDocument() to Pdoc to get the Notes Document. Otherwise it fails and you get the error "Error calling method 'copyItem(lotus.domino.local.Item)' on an object of type 'NotesXspDocument'".
Keep in mind that you have to save Pdoc after copying item too if you want to show the copied item in your exampleDialog.
If you don't want to save document Pdoc at this point yet then you can copy the item on NotesXspDocument level with just:
Pdoc.replaceItemValue("mytest1", Cdoc.getItemValueDateTime("mytest1"));
getComponent('exampleDialog').show()
I do not often use "copyItem". You are not specifying if you are using NotesDocuments or NotesXspDocuments, so I will write a quick thing about both because they should be handled differently.
var currentDoc:NotesDocument = ....
var newDoc:NotesDocument= ...
newDoc.replaceItemValue("fldname", currentDoc.getItemValueDateTimeArray("fldname").elementAt(0))
if currentDoc is a NotesXspDocument, use the following
var currentDoc:NotesXspDocument = ...
var newDoc:NotesDocument=...
newDoc.replaceItemValue("fldname", currentDoc.getItemValueDateTime("fldname"))
Otherwise, you could continue trying with copyItem, I just lack experience with it.
EDIT
Just some things to add, remember that putting calling xspDoc.getDocument(true) will update the background document and this might be needed. Also, in the comments for that article you posted, they mentioned the possible need to put that document into another variable.
var docSource:NotesDocument = xspDoc.getDocument(true);
var docNew:NotesDocument = ...
docNew.copyItem(docSource.getItem("blah");
Also remember that copyItem is a function of NotesDocument and not NotesXspDocument.
I'm trying to concatenate a string in Expression Language to access a property of an object and failing to do so.
Within an XPage in Lotus Notes, I want to programatically select which field to which I want to bind the control on the current XPage.
The result I would like to achieve is as follows.
#{poDoc[advertisingDateStart];}
I have a variable named fieldName that would supply "advertisingDate" and simply want to append "Start" to this field and "End" to the end date field. I tried several variations that do not work, such as:
#{poDoc[fieldName{'Start'}];}
Note that it would work if I passed in "advertisingDateStart" and used
#{poDoc[fieldName];}
The goal is to be able to place a start date field and an end date field while dynamically binding based on configuration documents. That is, adding fields to my XPage using configuration documents and repeats instead of changing the design. Here is one of the ways I tried to create the ending date field:
<xp:inputText id="inputText5"
style="padding-top:2px;text-align:left">
<xp:this.rendered><![CDATA[#{javascript:rowData.getColumnValue("FieldType") == "Date Range"; }]]></xp:this.rendered>
<xp:dateTimeHelper id="dateTimeHelper3"></xp:dateTimeHelper>
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
<xp:this.value><![CDATA[#{javascript:poDoc[fieldName+"End"];}]]></xp:this.value>
</xp:inputText>
I just can't figure it out.
Unfortunately, you cannot bind using 'javascript:' notation. In SSJS there is no way of pointing to an 'object property' (getter and setter) that you would like bound to component property.
Only Expression Language can do this with dot notation.
If you really need to bind to dynamic fields, you have to compute the fieldname before using it as Per Henrik Lausten suggested (xp:dataContext is the way to go). Since you want two date fields from one entry, you should use different variables for the new values, computing the value using Javascript
<xp:this.dataContexts>
<xp:dataContext var="fieldName">
<xp:this.value>
<![CDATA[#{javascript:rowData.getColumnValue ("FieldName");}]]>
</xp:this.value>
</xp:dataContext>
<xp:dataContext var="fieldNameDateStart">
<xp:this.value>
<![CDATA[#{javascript:return rowData.getColumnValue ("FieldName") + "Start";}]]>
</xp:this.value>
</xp:dataContext> <xp:dataContext var="fieldNameDateEnd">
<xp:this.value>
<![CDATA[#{javascript:return rowData.getColumnValue ("FieldName") + "End";}]]>
</xp:this.value>
</xp:dataContext>
</xp:this.dataContexts>
fieldName would be used for single field entries, while the others would be used only for start dates and end dates.
I know how to bind a computed field to a document field. And I know how to use javascript to compute a computed field. But how do I do both?
Say my javascript in the computed field is:
#Name("[ABBREVIATE]" ,#UserName());
How do I bind that to say document1.ReqName field?
I use two fields:
a hidden input field that computes the required value (using the xp:inputHidden control). I use "default value" to emulate Computed when composed - and converters to emulate Computed (inspired by Tommy Valand).
a visible computed field or a visible input field set to read only that does the same calculation. Perhaps this can be changed to display the value of the hidden input field using getComponent("").getValue()?
Maybe I miss the Point but why don't You simply do the following?
<xp:inputText id="inputText1" value="#{document1.Reader}">
<xp:this.defaultValue>
<![CDATA[#{javascript:#Name("[ABBREVIATE]",#UserName());}]]>
</xp:this.defaultValue>
</xp:inputText>
This is a Textfield bound per EL to the DocumentField. If the field is empty it is calculated by the default value.
Great! - I missed the point. But You can try this one:
<xp:text escape="true" id="computedField3">
<xp:this.value>
<![CDATA[#{javascript:
if(#IsNewDoc()){
document1.replaceItemValue("Reader",#Name("[ABBREVIATE]",#UserName()));
}
return document1.getItemValue("Reader");}]]>
</xp:this.value>
</xp:text>
For the computed field's Value, use Advanced data binding and select Expression Language (EL).
The expression to use is simply "document1.ReqName" (no quotes).
I wouldn't bind in this case. I would bind every other control and in this case manually add that into the document field directly with script before the save action.
so something like: (forgive the code not at my work comp)
<eventhandler>
<actionGroup>
<script><![CDATA[#{javascript:
doc.replaceItemValue("ReqName", #Name("[ABBREVIATE]" ,#UserName()));
}]]><script>
<saveDocument></saveDocument>
</actionGroup>
</eventhandler>
<xp:text escape="true" id="computedFieldTest1">
[CDATA[#{javascript:
var userName = "Username: "+("Reader",#Name("[ABBREVIATE]",#UserName()));
currentDocument.replaceItemValue("computedFieldTest1",userName);
return userName;
}]]></xp:this.value>
</xp:text>