
OTHER
Change a field value from a view on the Web
trevor wright 05.12.2003
Rating: -3.20- (out of 5)




|
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.
Code
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
 |

|
Rate this Tip
|
To rate tips, you must be a member of SearchDomino.com. Register now
to start rating these tips. Log in if you are already a member.
|


');
// -->
DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.
|
 |
|
|
 |
|
 |