flykarthick
flykarthick

Reputation: 79

Attach a file to a notes document using SSJS

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)

Upvotes: 0

Views: 2652

Answers (2)

Bill Hanson
Bill Hanson

Reputation: 91

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!");

Upvotes: 0

Frantisek Kossuth
Frantisek Kossuth

Reputation: 3524

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

Upvotes: 3

Related Questions