Subject: RE: How do i transfer attachment from one document to another
I’m sure Shweta has solved this but for latecomers trying to solve similar problems…
I have a web form with - thanks to www.the-stickman.com - multiple File Upload controls (hint: to successfully save the multiple fields, your Javascript should read the name of the control you placed on the form and re-use it for each additional control it creates). I use the same web form to create “addendums” to the original (via “&ParentUNID=”) and want the previous attachments pre-loaded whenever I create a new addendum.
Below is the core logic of the WebQueryOpen agent associated to the form.
Note:
ac_ = AgentContext
i__ = int
nd_ = NotesDocument
ni_ = NotesItem
s__ = String
v__ = Vector
(all lower-case because they’re local variables in my app)
ac_WebServer = getSession().getAgentContext();
nd_BeingOpened = ac_WebServer.getDocumentContext();
// Get the ParentUNID from the field hosting the CGI variable QUERY_STRING_DECODED
s__QueryStringDecoded = nd_BeingOpened.getItemValueString( “QUERY_STRING_DECODED” );
// Because getItemValueString(…) DOES rarely return null…
i__IndexOf = (s_QueryStringDecoded == null ? “” : s__QueryStringDecoded.toLowerCase()).indexOf( “parentunid=” ) + 11; // 11 skips past “=” if found; otherwise 11 plus -1 = 10
if( i__IndexOf >= 11 )
{ s__ParentUNID = s__QueryStringDecoded.substring( i__IndexOf, i__IndexOf + 32 );
nd_Parent = ac_WebServer.getCurrentDatabase().getDocumentByUNID( s__ParentUNID );
if( nd_Parent != null )
{ v__ParentItems = nd_Parent.getItems();
for( int i = 0; i < v__ParentItems.size(); i++ )
{ ni_Attachment = (Item) v__ParentItems.elementAt( i );
if( "$FILE".equalsIgnoreCase( ni_Attachment.getName() ) )
nd_BeingOpened.appendItemValue( "$FILE", ni_Attachment );
}
}
}
To solve Shweta’s problem, I would put similar code in a WebQuerySave agent, where I’d retrieve the desired document (instead of nd_Parent). To be sure document A doesn’t get saved, set its SaveOptions field to “0” (either in the form or the agent).