Creating backend document not generating computed fields

Hello All,
I have a lotus script that creates a backend document using fields from the current document that I have opened.
The problem is the computed fields on the backend document do not get computed.  The backend document has a dblookup to auto create a number and that field is coming out blank.  The dae field which uses @Created is coming out blank.
Is there a way to get the backend document to generate the computed fields as it does if I created it directly ????
Thanks !
Who is Participating?
Sjef BosmanGroupware ConsultantCommented:
The statement
    doc.Form = "ORRform"
just sets an item called Form to a value. Only when the document is opened, then the value in the Form-item is used. Consequence: you can save a document without a Form-item in it, and Notes will not complain. If you would try to open that document, then Notes will complain, for it doesn't know how to present the data (using a form).

Just call
    doc.computewithform(false, false)
Then, no error will be generated, so you could end up with a document with errors in the fields. You can of course check the flag return value.
Sjef BosmanGroupware ConsultantCommented:

A DOCUMENT doesn't have DbLookup's, a FORM does. So if you create a backend-document without using a form, fields (in this case you'd better talk about ITEMs) do not get computed. Add an item Form to the backend document, and use the ComputeWithForm method to force computation of all items.

pratiganAuthor Commented:
Hello Sjef,
Sorry for the misconception.  I do use a form statement.  Here is the script for the generating of the backend doc.
Sub Querysave(Source As Notesuidocument, Continue As Variant)
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim ws As New NotesUIWorkspace
      Dim uidoc As notesuidocument
      Dim doc As notesdocument
      Dim backendDoc As NotesDocument
      Set db = ss.CurrentDatabase
      Set uidoc = ws.CurrentDocument
      Set backendDoc = uidoc.Document
      Set doc = db.CreateDocument
      doc.Form = "ORRform"
      doc.ORrequest = backendDoc.DisplayAuthor(0)
      doc.ORjob_nme = backendDoc.jclmember(0)
      doc.ORappl = backendDoc.Subsystem(0)
      doc.ORdesc = backendDoc.rpt1(0)
      doc.ORrpt = backendDoc.rpt1_rpt_ID(0)
      doc.ORwriter = backendDoc.rpt1_wrtr_nam(0)
      numlook = "@If(@IsNewDoc;@Subset(@DbColumn( '' : 'NoCache' ; '' : '' ; '(ORreq)' ; 1 );1)+1;ORreq)"
      doc.ORreq = Evaluate(numlook)
      doc.ORreq_Date = backendDoc.DisplayDateCreated(0)
      Call doc.Save(True,False)
      Call backendDoc.Save(True,False)
End Sub
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Sjef BosmanGroupware ConsultantCommented:
And which doc is uncorrectly computed: backendDoc or doc? If it is backendDoc, I have to scratch my head, but if it is doc, then I'm right all the way, for there is no FORM involved: you just write a document and save it. Check out the ComputeWithForm method.

PS You don't have to call backendDoc.Save, it is the QuerySave of the uidoc so the document will be saved anyway (unless you set continue to False)
Sjef BosmanGroupware ConsultantCommented:
Btw I assume the first 9 lines of the code in the function are pasted in, to keep things pretty standard? If not, you could remove some of the code, since uidoc= source, and db=doc.parentdatabase.
pratiganAuthor Commented:
Hello Sjef,
Your correct.  First, the first 9 lines are copied in.  I use them for all my scripts as a template per say.
also, doc is the document getting created.  I thought that the
doc.Form = "ORRform" statement tied the script to the form.
But you say no form is involved.
I'm currently reviewing the computewithform logic.
it appears to be used with a flag situation.  is there a way to just call it ?
flag = notesDocument.ComputeWithForm( doDataTypes, raiseError )
Boolean. The method ignores this parameter. Specify either True or False.
Boolean. If True, an error is raised if the validation fails. If False, no error is raised; instead, the method returns False if validation fails.
pratiganAuthor Commented:
I think I got it.  I understand the If is checking the validation of the fomulas in the new doc.
I'll get back to you with my status.
Thanks !
pratiganAuthor Commented:
Well, I'm see much of a difference.  the DBcolumn to autogenerate the number field is not working and and computed field that takes the value of a previous field ajnd manipulates it isn't working.  Menaing: I have a jobname field that position 4 indicates job run frequency.
I have this in the frequency field of the new doc;
However if I try to do this in script as it doesn't auto generate in the new doc itself I use:
doc.ORfreq = Mid$(backendDoc.jobname$, 4, 1)
and all I get is mismatch type error.
pratiganAuthor Commented:
OK.... got the frequency working... just need to get the dbcolumn on the number field to work.
Sjef BosmanGroupware ConsultantCommented:
Whaddayamean? The numlook variable? I already had my doubts the first time, I fear that an Evaluate() with an @DbLookup won't work, but I'm not sure... Now I am, after reading "Using the Evaluate statement" in the Designer Help. Back to the drawing board ;)
pratiganAuthor Commented:
I have everything working except;
The new document to create has an auto numbering formula that performs a dbcolumn lookup on a view to get the last number used and adds 1 to it:
@If(@IsNewDoc;@Subset(@DbColumn( "" : "NoCache" ; "" : "" ; "(ORreq)" ; 1 );1)+1;ORreq)
Although its a computed field, it's not getting generated.
Thanks Sjef.
Sjef BosmanGroupware ConsultantCommented:
Why not open the view using LS?
    Dim view As NotesView

    Set view= db.getview("(ORreq)")
    set vdoc= view.getfirstdocument
    If vdoc Is Nothing Then
        doc.ORreq= 1
        doc.ORreq= vdoc.ORreq(0) + 1
    End If

pratiganAuthor Commented:
It's that simple.......
You made it sound too easy.
And it worked like a Charm.  
Thank you Very Much !!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.