Attach a file to a notes document using SSJS - lotus-notes

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)

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

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

Related

nlapiCreateRecord and nlapiLoadRecord throwing syntax error

I am getting the following wherever I am using nlapiLoadRecord or nlapiCreateRecord in the suitescript(1.0):
"error": {
"code": "UNEXPECTED_ERROR",
"message": "syntax error (NLRecordScripting.scriptInit$lib#151)"
}
Following is the code snippet
if(datain.internalid != null){
record = nlapiLoadRecord('supportcase',datain.internalid);
}else{
record = nlapiCreateRecord('supportcase');
}
Can anyone help with this?
There is a User Event running on beforeLoad that has an error in it; based on the error, I would look for a file containing a reference like NLRecordScripting.scriptInit on line 151.

xpages send mail to a specific address

I try to create a button which send a mail using the doc's URL to a mail-adress entered in an editBox:
if(Contr.isNewNote()){
Contr.save();
}
var thisdoc = Contr.getDocument(true);
var tempdoc = database.createDocument();
tempdoc.replaceItemValue("Form", "Memo");
tempdoc.replaceItemValue("SendTo", thisdoc.getItemValue("Destinatari"));
tempdoc.replaceItemValue("Subject", "My application");
var tempbody:NotesRichtextItem = tempdoc.createRichTextItem("Body");
tempbody.appendText("Click for open the doc. in client")
tempbody.addNewLine(2);
tempbody.appendDocLink(thisdoc);
tempbody.addNewLine(2);
thisdoc.save(true,true);
tempbody.appendText("click for navigating via web")
tempbody.addNewLine(2);
tempbody.appendText(facesContext.getExternalContext().getRequest().getRequestURL().toString() +
"?action=readDocument&documentId=" + thisdoc.getUniversalID());
tempdoc.send();
thisdoc.recycle();
tempbody.recycle();
tempdoc.recycle();
But at tempdoc.send(); I get Exception occurred calling method NotesDocument.send() null
What is weird, is the fact that for an application on the same server the code is working, I just copy the code and just modified the doc datasource and the SendTo field name. Am I missing something? Thanks for your time.
I forget the issue but there's been reports of this problem I think if a bad character gets into the sendTo.
There's a comment on the email bean XSnippet: http://openntf.org/XSnippets.nsf/snippet.xsp?id=emailbean-send-dominodocument-html-emails-cw-embedded-images-attachments-custom-headerfooter
that said:
The solution that seems to work is to use the method :
emailHeader.addValText(xxx,"UTF-8")
instead of
emailHeader.setHeaderVal(xxx)
I'm not exactly sure how that might translate to SSJS.. but the problem might be with special characters..

Error during run OrganizationRequest 'RetrieveAllEntities'

I got this error during execute, could anyone give suggestion? Thanks
OrganizationRequest oreq = new OrganizationRequest();
oreq.RequestName = "RetrieveAllEntities";// please google for available Request Names
oreq.Parameters = new ParameterCollection();
oreq.Parameters.Add(new KeyValuePair<string, object>("EntityFilters", EntityFilters.Entity));
oreq.Parameters.Add(new KeyValuePair<string, object>("RetrieveAsIfPublished", false));
OrganizationResponse respo = orgProxy.Execute(oreq);
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/xrm/2011/Contracts/Services:ExecuteResult. The InnerException message was 'Error in line 1 position 727. Element 'schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data of the 'schemas.microsoft.com/xrm/2011/Metadata:ArrayOfEntityMetadata' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfEntityMetadata' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details."
Add a reference to Microsoft.Crm.Sdk.Proxy and Microsoft.Xrm.Sdk. Visual Studio may tell you that you need to add an additional couple System.* references - add them.
Use this code:
IOrganizationService service = GetCrmService(connectionString); //This is a helper, just need to setup the service
var request = new Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesRequest()
{
EntityFilters = Microsoft.Xrm.Sdk.Metadata.EntityFilters.All,
RetrieveAsIfPublished = false
};
var response = (Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesResponse)service.Execute(request);
Get it work finally there is two KnownTypeAttribute need to be added to the proxy class
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationRequest : object, System.Runtime.Serialization.IExtensibleDataObject
....
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationResponse : object, System.Runtime.Serialization.IExtensibleDataObject
Thank you for help.

JAXB unmarshalling a xml with inclusions

I have a xml below called “TheFile.xml”
<!DOCTYPE page [
<!ENTITY class_common SYSTEM "class_common.xml" >]>
<api xmlns:denp="http://intranet.denali.com/wiki/DocBook_profiling">
&class_common;
As you can see the line above refers to another xml file called “class_common.xml” . However, when I do
cl = class_xml.ObjectFactory.class.getClassLoader();
context = JAXBContext.newInstance("class_xml", cl);
Unmarshaller u = context.createUnmarshaller();
api = (Api) u.unmarshal(new FileInputStream(classXMLFile));
I get some error like the following. Did I miss anything? Thanks
Exception in thread "main" javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 17; External Entity: Failed to read external document 'class_common.xml', because 'file' access is not allowed due to restriction set by the accessExternalDTD property.]
Ok, here is the answer, the Java code needs to be like the following
cl = class_xml.ObjectFactory.class.getClassLoader();
context = JAXBContext.newInstance("class_xml", cl);
Unmarshaller u = context.createUnmarshaller();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setXIncludeAware(true);
spf.setNamespaceAware(true);
spf.setValidating(true); // Not required for JAXB/XInclude
XMLReader xr = (XMLReader) spf.newSAXParser().getXMLReader();
SAXSource source = new SAXSource(xr, new InputSource(new
FileInputStream(classXMLFile)));
api = (Api) u.unmarshal(source);

xpages Trying to get document parentdoc is returning null error

I am trying to get the parent document of a new response document so I can duplicate the functionality of form inheritance in xpages. The following is my code and the error being returned:
Error while executing JavaScript action expression
Script interpreter error, line=3, col=60: 'parentDoc' is null
JavaScript code
1: if (document2.isNewNote()) {
2: var parentDoc:NotesDocument = database.getDocumentByID(document2.getParentId());
3: getComponent("immediateParentSubject1").setValue(parentDoc.getItemValueString("Subject"));
4: }
I usually use a dataContext and getParentDocumentUNID() when I need a handle on the parent document for the variable "document". You can use this for a new document (not saved yet):
<xp:this.dataContexts>
<xp:dataContext var="parentDoc">
<xp:this.value><![CDATA[#{javascript:
try {
if (document.isResponse()) {
return database.getDocumentByUNID(document.getDocument().getParentDocumentUNID());
} else {
return "";
}
} catch(e) {
return "";
}}]]></xp:this.value>
</xp:dataContext>
</xp:this.dataContexts>
You can then use parentDoc in other controls and do parentDoc.getItemValueString("Subject") etc.
datasource.getParentId() does not return the NoteID as you might expect. It returns the UnID and that's why you need to use database.getDocumentByUNID as Per is doing.
Another way is to get the parent UnID from the URL:
param.get("parentId")
Consider also looking up the parent subject whenever a child is opened instead. That way it is stored only in one place which is always a good thing.

Resources