In our current project, we create Requisitions with one XPage and then create Purchase Orders with another. Each Requisition may result in many Purchase Orders, but a Purchase Order can only contain line items from a single Requisition. Naturally, the customer wants to be able to move seamlessly from the Requisition to any of the corresponding Purchase Orders and vice-versa.
I wasn’t sure how I’d do this in XPages, but knew I could do it for Notes users without a lot of coding and I could even make it look like web link.
One-to-One In Notes
In regular old Notes, this was very simple. On the Purchase Order form, where I wanted my link I typed Open Procurement Request, then highlighted it and clicked from the top-line menu, Create – Hotspot – Action Hotspot. I made two formatting changes (underline and deselecting the border around the hotspot) 1 and switched the action to run LotusScript. Nice, simple code makes that hotspot open the Requisition:
Sub Click(Source As Button) Dim session As New NotesSession Dim ws As New NotesUIWorkspace Dim thisdb As NotesDatabase Dim view As NotesView Dim uidoc As NotesUIDocument Dim thisdoc As NotesDocument Dim reqdoc As NotesDocument Dim luvalue As Variant Set uidoc = ws.CurrentDocument Set thisdoc = uidoc.Document luvalue = thisdoc.GetItemValue ( "ProcReqDocID" ) Set thisdb = session.CurrentDatabase Set view = thisdb.GetView ( "LUProcByDocID" ) Set reqdoc = view.GetDocumentByKey ( luvalue(0) ) Print luvalue (0) If Not reqdoc Is Nothing Then Call ws.editDocument ( False, reqdoc ) End If End Sub
One-to-One In XPages
Having done it in Notes, I had some guidelines for how I wanted to do it in XPages, rather than just shooting in the dark. I also added display of the requisition number, which turned out to take a few lines of code as well.
<xp:link escape="true" id="requisitionLink" target="_blank"> <xp:this.rendered><![CDATA[#{javascript:poDoc.getItemValueString("ProcReqDocID") != "";}]]> </xp:this.rendered> <xp:this.text><![CDATA[#{javascript: var reqID = poDoc.getItemValueString("ProcReqDocID"); var db:NotesDatabase = getDb("tamisDb"); var reqView:NotesView = db.getView("LUProcByDocID"); var reqDoc:NotesDocument = reqView.getDocumentByKey(reqID); var reqNumber = reqDoc.getItemValueString("TSWFNumber"); return "Requisition: " + reqNumber; }]]> </xp:this.text> <xp:eventHandler event="onclick" submit="true" refreshMode="complete"> <xp:this.action> <xp:openPage name="/pro_procurementRequest.xsp" target="openDocument"> <xp:this.documentId><![CDATA[#{javascript: var reqID = poDoc.getItemValueString("ProcReqDocID");; var db:NotesDatabase = getDb("tamisDb"); var reqView:NotesView = db.getView("LUProcByDocID"); var reqDoc:NotesDocument = reqView.getDocumentByKey(reqID); return reqDoc.getUniversalID();}]]> </xp:this.documentId> </xp:openPage> </xp:this.action> </xp:eventHandler> </xp:link>
While this was somewhat intimidating, it ended up being not that hard. I will admit that it did take me a whole day to figure out, but it gave me the courage to try tackling linking in the opposite direction, our one-to-many link. For that, I had to expand my recently gained knowledge of repeats. More on that later.
My recent knowledge gain for repeats is thanks to TeamStudio’s webinar on mobile applications. Go figure. As I implement the mobile application that the webinar guided me through building, I’ll blog about that as well. For now, go check out the video.
1) Does anyone use those borders around the hotspot anymore? Since it looks so hideously and is therefor unusable shouldn’t it no longer be the default? Shouldn’t it instead default to underlined?
Pingback: Creating one-to-many linking in Xpages | Lost in XPages, Soon to be Found