Manage Learn to apply best practices and optimize your operations.

Change a field value from a view on the Web

This tip describes how to change a field value from a view on the Web.

We needed to be able to update a document from a view, without opening the document. I used a $$ViewTemplate and in the view column added an html field to allow the value to be changed and when changed call a JavaScript function to run an agent to change the field value and reload the form.


in the view column:
temp := @DocNumber("");
"<tr><td><input type=text  
id=chField"+ temp+ " onChange=chTAS
("" +@Text(@DocumentUniqueID) + """ +  
"," +  """ +temp   +  "") value=""+
PPriorityRO +""></td>"

in the JSHeader:
function chTAS(uid ,pval){
var f = document.forms[0];
var refer = f.HTTP_Referer.value;
if(refer ==""){
refer = "http://" + f.Cluster_Name.value 
+ "/" + f.DBName.value; 
}
var ch = "f.chField" + pval + ".value";
var npval =  eval(ch);
OpenAgent&UNID=" + uid + "&PVal=" + ch;
var strurl = refer + "/sTASPri?
OpenAgent&UNID=" + uid + "&PVal=" + npval;
this.location = strurl;
}
Agent to save document & refresh the view:
Dim db As NotesDatabase
Dim agent As NotesAgent
Dim server As String
Dim view As NotesView
Dim webDoc, doc As notesDocument
Dim urlstr As String
Dim agentLog  As NotesLog
Dim dbname As String
Dim ename As String
Dim tmpvar As Variant
Dim evalstr As Variant
Dim DocID As String
Dim querystring As String
Dim unid As String
Dim wunid As String
Dim prival As String
Dim UID As String
Dim wView As notesview
Dim wDb As notesdatabase
Dim wDoc As notesdocument
Dim wKey As String
Dim newname As String
Dim referer As String
Dim priority As String


Sub Initialize
 On Error Goto errHandler
 Dim session As New notessession 
 Set agentLog = New notesLog
("Save TASPriorities Log Info")
 Call agentLog.OpenAgentLog 
 Set db=session.currentdatabase
 Set webDoc = session.DocumentContext
 
 referer = webdoc.HTTP_Referer(0)
 Set view = db.GetView("TASPRO")
 evalstr = "@ReplaceSubString
(@SubSet(@DBName;-1);"""";""/"")"
 tmpvar = Evaluate(evalstr)
 dbname = Cstr(tmpvar(0))
 querystring=webDoc.Query_String(0)
 
 priority = webdoc.PPriority(0)

 If(Instr(querystring,"&UNID=") >0)Then
  wunid$ = parsequerystringforentry
(querystring,"&UNID=")
  prival$ = parsequerystringforentry
(querystring,"&PVal=")
  Dim newfld As Variant
  Call setdoc(wunid$,prival$)
  Call agentLog.Close
  Exit Sub
 Else
  wunid$ = webdoc.UIDCheck(0)   
 End If

 eName = parsequerystringforentry
(querystring,"&Name=")

 If(eName <> "")Then  
  Call replace20(eName,newname)
 End If

 If(wunid$ <> "") Then
  Set doc = db.getdocumentbyUNID
(wunid$) 
 Else 
  Goto newDoc
 End If
 
 If Not doc Is Nothing Then
  unid$ = doc.UniversalID
  doc.PPriorityRO=webdoc.PPriority(0)
  doc.PNameRO=newname
  doc.PSearchIDRO = webdoc.PSearchID(0)
  doc.PWIDRO = webdoc.PWID(0)
  doc.PAppIDRO = webdoc.PAppID(0)
  doc.PEstHoursRO =  webdoc.PEstHours(0)
  doc.PDueDateRO = webdoc.PDueDate(0)
  doc.PPCompRO = webdoc.PPComp(0)
  doc.PHrsRemRO = webdoc.PHrsRem(0)
  doc.PTAllocRO = webdoc.PTAlloc(0)
  doc.PStatusRO = webdoc.PStatus(0)
  Call doc.save(True,True)
 Else 
newDoc:
  Set doc = db.CreateDocument
  doc.form = "TASPRO"
  doc.PPriorityRO=webdoc.PPriority(0)
  doc.PNameRO=newname
  doc.PSearchIDRO = webdoc.PSearchID(0)
  doc.PWIDRO = webdoc.PWID(0)
  doc.PAppIDRO = webdoc.PAppID(0)
  doc.PEstHoursRO = webdoc.PEstHours(0)
  doc.PDueDateRO = webdoc.PDueDate(0)
  doc.PPCompRO = webdoc.PPComp(0)
  doc.PHrsRemRO = webdoc.PHrsRem(0)
  doc.PTAllocRO = webdoc.PTAlloc(0)
  doc.PStatusRO = webdoc.PStatus(0)
  Call doc.save(True,True)
 End If 
 
 urlstr = "/" + dbname+ "/$$TASPRO?
OpenForm&Name=" & newName
 
 Print "[" +  urlstr + "]"
 Call agentLog.Close
 
 Exit Sub 
errHandler:
 Print "<a>Error in Save (sTASPri) 
Line# " + Format$(Erl()) + ": " + Error$ +"
 (" + Cstr(Err) + ")<a>"
End Sub

Sub setdoc(sunid As String,prval As String)
 Set doc = db.getdocumentbyunid(sunid)
 If Not doc Is Nothing Then
  doc.PPriorityRO = prval
  newname = doc.PNameRO(0)
  Call doc.save(True,True)
  urlstr = "/" + dbname+ "/$$TASPRO?
OpenForm&Name=" & newName
 End If
End Sub
  
 

Dig Deeper on JavaScript for Lotus Notes Domino

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close