0
votes

I am trying to attach a file to notes document, but I am getting the following error.

 var doc:NotesDocument = DS_EmpDetails.getDocument();
 var rtitem:NotesRichTextItem = doc.createRichTextItem("AttachmentField");
 var Attachment:String = "C:\\Users\\karthick_m\\Desktop\\PDFIcon.jpg"; 
 var emobj:NotesEmbeddedObject = rtitem.embedObject(NotesEmbeddedObject.EMBED_ATTACHMENT, "", Attachment, null);
 doc.save();

I am getting the following error..

 [TypeError] Exception occurred calling method NotesRichTextItem.embedObject(number, string, string, string) null

Thanks in Advance...

My Stack Trace Stack Trace

javax.faces.FacesException: Error while executing JavaScript action expression com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:102) com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96) com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:250) com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:206) com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:189) com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:154) com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:137) com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:86) com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:538) com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1140) com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:803) com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:758) com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:527) com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1124) com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:513) com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:342) com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:304) com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:261) com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:291) com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression com.ibm.xsp.binding.javascript.JavaScriptMethodBinding.invoke(JavaScriptMethodBinding.java:126) com.ibm.xsp.application.ActionListenerImpl.processAction(ActionListenerImpl.java:60) javax.faces.component.UICommand.broadcast(UICommand.java:324) com.ibm.xsp.component.UIEventHandler.broadcast(UIEventHandler.java:365) com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400) com.ibm.xsp.component.UIViewRootEx.broadcast(UIViewRootEx.java:1490) javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:307) javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:428) com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:94) com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96) com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:250) com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:206) com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:189) com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:154) com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:137) com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:86)

2
please, paste 5-10 lines from stacktrace - Frantisek Kossuth
is your file on server? SSJS runs on server, so file you want to attach must be accessible on server - according to "users\..." part of path it seems you have file on client only. - Frantisek Kossuth
@FrantisekKossuth: My file is on client machine(local desktop). And I am calling this ssjs by clicking on the button from the browser. - flykarthick
The error is raised because the file is not found from the SSJS code. Are you running a local server or is the XPage running in the Notes Client? - Sven Hasselbach
@SvenHasselbach: I am not running on the local server and the XPage is not running on the Notes Client. I am previewing from web browser(eg. Chrome, not client). I want to attach a file from the current machine in a notes document on a button click in the browser. I know the path of the file. So I tried to attach using SSJS. Where as I don't want to use FileUpload Control in Xpage. - flykarthick

2 Answers

3
votes

Use Upload control. The way you use SSJS code is working only for file already on server - you did not upload it.

0
votes

The error message above may be wrong, but it states that the cause is that the 'rtitem' variable is null. Have you checked this in your code?

if (!rtitem) throw new java.lang.Exception("Uh oh!");