Reputation: 211
My database allow Anonymous to access the database and submit form to do process It have 3 roles inside [Applicant],[Admin],[Reviewer]
problem:
I need to update "Email" field by combining 3 different "mail" field to combine it. So i use add element but it seem save wrong data, it give an extra [applicant]. Attached image will display how it display
var v;
// Update mail 1 and mail 2 and mail3 into Email field!
if
(
(document1.getValue("Mail1")!=null && document1.getValue("Mail1")!="")&&
(document1.getValue("Mail2")!=null && document1.getValue("Mail2")!="")&&
(document1.getValue("Mail3")!=null && document1.getValue("Mail3")!="")
) //all not empty
{
v.addElement(document1.getValue("Mail1")+"@brookedockyard.com.my");
v.addElement(document1.getValue("Mail2")+"@brookedockyard.com.my");
v.addElement(document1.getValue("Mail3")+"@brookedockyard.com.my");
document1.replaceItemValue("Email",v)
else if
(
(document1.getValue("Mail1")!=null && document1.getValue("Mail1")!="")&&
(document1.getValue("Mail2")==null && document1.getValue("Mail2")=="")&&
(document1.getValue("Mail3")===null && document1.getValue("Mail3")=="")
) // only have mail 1
{
document1.replaceItemValue("Email", document1.getValue("Mail1")+"@brookedockyard.com.my")
}
else if
(
(document1.getValue("Mail1")!=null && document1.getValue("Mail1")!="")&&
(document1.getValue("Mail2")!=null && document1.getValue("Mail2")!="")&&
(document1.getValue("Mail3")==null && document1.getValue("Mail3")=="")
) // only have mail 1 and mail 2
{
v.addElement(document1.getValue("Mail1")+"@brookedockyard.com.my");
v.addElement(document1.getValue("Mail2")+"@brookedockyard.com.my");
document1.replaceItemValue("Email",v)
else if
(
(document1.getValue("Mail1")!=null && document1.getValue("Mail1")!="")&&
(document1.getValue("Mail2")==null && document1.getValue("Mail2")=="")&&
(document1.getValue("Mail3")!=null && document1.getValue("Mail3")!="")
) // only have mail 1 and mail 3
{
v.addElement(document1.getValue("Mail1")+"@brookedockyard.com.my");
v.addElement(document1.getValue("Mail3")+"@brookedockyard.com.my");
document1.replaceItemValue("Email",v)
}
i am using serverside javascript to save document. But during save it add extra information inside the system.
Upvotes: 1
Views: 160
Reputation: 1260
Create a request scoped bean.
faces-config.xml
<managed-bean>
<managed-bean-name>forgetSsjs</managed-bean-name>
<managed-bean-class>demo.bean.ForgetSsjsBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
the bean
package demo.bean;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import lotus.domino.NotesException;
import com.ibm.commons.util.StringUtil;
import com.ibm.xsp.model.domino.wrapped.DominoDocument;
import com.ibm.xsp.util.FacesUtil;
public class ForgetSsjsBean implements Serializable {
private static final long serialVersionUID = 1L;
public void saveTheDoc() {
FacesContext facesContext = FacesContext.getCurrentInstance();
DominoDocument wrapper = (DominoDocument) FacesUtil.resolveVariable(facesContext,
"document1");
Set<String> emails = new HashSet<String>();
try {
for (int i = 1; i < 4; i++) {
addEmail(wrapper.getItemValueString("Mail" + i), emails);
}
if (!emails.isEmpty()) {
wrapper.replaceItemValue("Email", new Vector<String>(emails));
wrapper.save();
}
} catch (NotesException e) {
throw new FacesException(e);
}
}
private void addEmail(String name, Set<String> emails) {
if (StringUtil.isEmpty(name)) {
return;
}
emails.add(name + "@brookedockyard.com.my");
}
}
Link your event handler action to the method you destine for saving the document:
the xsp page
<xp:this.data>
<xp:dominoDocument var="document1" ... />
</xp:this.data>
...
<xp:button id="button1" value="save this thing">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" action="#{forgetSsjs.saveTheDoc}" />
</xp:button>
Upvotes: 1
Reputation: 30960
I think your code needs some optimization. This code does the same as yours:
var v = [];
["Mail1", "Mail2", "Mail3"].forEach(function(name) {
if (document1.getValue(name)) {
v.push(document1.getValue(name)+"@brookedockyard.com.my");
}
});
document1.replaceItemValue("Email",v);
In addition it initializes the variable v
as an empty array. Use arrays instead of Vectors when possible. It's more JavaScript native.
Upvotes: 4
Reputation: 15729
Where is your Vector (v
) created? You're just adding elements to that existing Vector, so your code (Form setting if using computeWithForm, XPage setting, SSJS code) must be initialising that Vector with an "[Applicant]" value or retrieving a Vector that already includes the "[Applicant]" value.
The chances of IBM code adding "[Applicant]" to the Item during the setValue()
method are nil. The bug is almost certainly in your application code, not introduced by setValue()
. Eclipse search should help identify where application code is setting that value.
Upvotes: 3