Link to home
Start Free TrialLog in
Avatar of David Schmalzer
David SchmalzerFlag for United States of America

asked on

Field Modification

I would like to stamp the name of the person along with the date and time of the person who modifies a field(only that field, not the document)next to that field. How can I do this?
Avatar of snocross
snocross

I suppose you could have two fields and hide one of them.  When the form is resaved you can compare the two values and if they are different then 1) Record the name of the user in a 3rd field and 2) Set the hidden value equal to the first.

Anybody have any other suggestions?
In the postopen event of the form carry this field content to the environment variable.

While saving check this fields content with that of the environment variable.

If they are same dont do anything just clear the environment variable.

If they are different then stamp the field with the sessions username and the date and time (now).

-Arun.
Sno! you were as lightening on this one.  I had a conversation with Samir.Mistry while you got this one DAMN!
missed to clear environment variable in the second option

If they are different then stamp the field with the sessions username and the date and time (now) and clear the environment variable.

That was 20 mins late too Sno!
Ha ha ha, this is fun!
Are we getting back to some action here like we used to ???
Avatar of David Schmalzer

ASKER

30 mor points for details and code.
Postopen event of the form

If Not Source.IsNewDoc Then
     Call s.SetEnvironmentVar("FieldNameVariable" , Source.FieldGetText("FieldName"))
End If

QuerySave of the form

Dim ss as new notessession
msg = ss.CommonUserName & " Modified at " & Cstr(Now)

If Source.FieldGetText("FieldName") <> ss.GetEnvironmentString("FIELDNAMEVAriable") Then
Call Source.FieldSetText("SecondFieldName" , msg )
End if
Call ss.SetEnvironmentVar("FieldNameVariable" , "" )

-Arun.
FIELD1
Type: Editable

FIELD2
Type: Computed
Value: FIELD1Name
Hide Formula: Hide always

FIELD3
Type: Computed
Formula Value:
@If(FIELD1 = FIELD2;"";@Do(@SetField("FIELD3";@Username);@SetField("FIELD2";FIELD1)))
Darn!
Schmad01 is getting excellent service response today!
You are missing a lot today Sno... And i think its my day today....
What about the date and time?
FIELD3
Type: Computed
Formula Value:
@If(FIELD1 = FIELD2;"";@Do(@SetField("FIELD3";@Text(@Username)+" "+@Text(@Now));@SetField("FIELD2";FIELD1)))
You're both doing excellent. I appreciate it.
I think we forgot 1 field. Let me set it up this way:

FIELD1(drop-down Yes or No - default is blank) FIELD2(The person's name who creates or modifies FIELD1-computed) FIELD3(The date and time created or modified)

If FIELD1 gets modified by someone else, then I would like FIELD2 to reflect that with the new person's name.

Now I want FIELD2 and FIELD3 to show the user and time only if FIELD1 is populated or changed, not if the whole document is modified.

Does that explain it any better? Let me know.
yes !

But my code uses only field 1 and field 2. Where field 2 tracks the user name and the date and time together.

Did you test my code ?
Yes, everything stayed blank.  Maybe I overlooked something. I'll try again.
If this was a web application it would be a lot easier to do this.
You can just compare the value with the defaultValue in JavaScript. If they're not the same, the field has changed and you need to set the modifiedBy field, otherwise you leave the modifiedBy field alone.

If this is something you can use, let me know and I'll go into further detail for you, so you can work it out for your specific needs.

I'm not sure if the same JavaScript functions would also work in the client. Some JavaScript does, some doesn't.
I'd have to try to see, but first let me know if you're interested in this solution or not.

Regards,
JM
Ok just change FIELD3 to remove the time reference and add a FIELD4:

FIELD3
Type: Computed
Formula Value:
@If(FIELD1 = FIELD2;"";@SetField("FIELD3";@Username))

FIELD4
Type: Computed
Formula Value:
@If(FIELD1 = FIELD2;"";@Do(@SetField("FIELD4";@Now);@SetField("FIELD2";FIELD1)))
Well, with JavaScript you only need three fields:
One field to hold the value and one field to hold the modified date/time and a third to hold the user name of the person that last edited the field.
These last two, can be combined into one if needed too.
I like Javascript too but he hasn't mentioned anything about the web.... OnChange() event right?
Yep, that would do the trick :-)
This should also work in the client IIRC. Anyway, I'll wait for schmad01 to get back to us, before I elaborate on the topic.
Thanks, jerrith, but no Web. I will try snocross's latest.
I think because FIELD2 is computed to take FIELD1's value, they will always be equal and maybe that is why I am getting blanks for Username and Time?
I think you're right. (I haven't really looked at it yet).
But the logic would be like this:
In QuerySave event:
Formula's for old values field should be the name of the old Values field and not of the original field, this way the value isn't changed automatically.

Then in QuerySave event do the following:
1) Compare value field and old value field, if different, set editor and date stamp field.
2) Set old value field equal to value field.

If you do it in this sequence, it should work perfectly.
Schmad01, if you're using my example then I think you just need to move field2 so it is after the other two fields.  The problem is with the order of things evaluating.  Field1 and Field2 were becoming equal before the username and time could be set.  If you put the field3 and field4 between field1 and field2 then your problem should be solved.

-Sno
OK, here is what is happening now after changing order. Now, My name comes up in FIELD3 where it should be. But whatever I select in the dropdown from FIELD1 shows up in FIELD4 after refreshing.  Can we start over? I'm getting confused.!$#@%^&*#
Ok, you are very very close... what is your formula for field4?
don't you get mad schmad
that will make us a tad sad
soon you'll be rad glad

Note: No extra cost for the haiku
That was a good one Sno!
Yes, I have way too much time apparently
Not mad, just confused. This is the formula I used for FIELD4.

@If(FIELD1 = FIELD2;"";@Do(@SetField("FIELD4";@Now);@SetField("FIELD2";FIELD1)))
Yes but confused does not rhyme so well....  Ok that formula looks ok... I wonder if somewhere else you are also setting field4 therefore overwriting the time value.  Maybe you can post all of your formulas?  Or you can send me the db if you want...
Okay I am gonna snatch the pts or share the pts here is the refined formula of Snocross....

FIELD 3
Type Computed
Formula Value

@If(FIELD1 = FIELD2 ; FIELD3 ;@UserName )

FIELD 4
Type: Computed
Formula Value:

@If(FIELD1 = FIELD2; FIELD4 ; @Do(@SetField("FIELD4";@Now);@SetField("FIELD2";FIELD1)))

Got it ?

Now I have a headache!
Let me increase the pounding a little.  Ok FIELD1 is a drop down. The keyword choices are Y or N. Now here is what is happening after all the fields are in the right order and all the codes in place. This is what is coming up.

FIELD1--Let's say I pick N.
FIELD3--My name.
FIELD4--N
FIELD2(hidden)--N

I need the time and date to appear for FIELD4.
Ok, somewhere there is a problem with a formula... somewhere the code is saying to replace Field4 with Field1.  Can you post the code for your fields that contain code?
Forget All Sno's ideas.  I have a working solution right with me....

Follow these instructions carefully...

FIELD1 is Keywords. Editable.
(This field should be tracked for changes !)
FIELD2 is computed Text with value as Field2
(This will hold the username who modified or created that field with whatever values)
FIELD3 is computed Text with value as Field3
(This will be tracking the date and time of the modification of the first field)

You can have any additional fields if you would like....for testing.

In the postopen event of the form have the following code.

Sub Postopen(Source As Notesuidocument)
     Dim s As New notessession
     If Not Source.IsNewDoc Then
          Call s.SetEnvironmentVar("KeyFieldVal" , Source.FieldGetText("Field1"))
     End If
End Sub


----------------------------------------

In the QuerySaveEvent have the following code.



Sub Querysave(Source As Notesuidocument, Continue As Variant)
     Dim ss As New notessession
     un = ss.CommonUserName
     dat = Cstr(Now)
     If Source.IsNewDoc Then
          Call Source.FieldSetText("Field2" , un )
          Call Source.FieldSetText("Field3" , dat )
     Elseif Source.FieldGetText("Field1") <> ss.GetEnvironmentString("KeyFieldVal") Then
          Call Source.FieldSetText("Field2" , un )
          Call Source.FieldSetText("Field3" , dat )
     End If
     Call ss.SetEnvironmentVar("FieldNameVariable" , "" )
End Sub


THATS ALL.... I have tested it to perfection.  If you need more assistance i can send you the db itself send me your email.

:-)
Arun.
Sorry Sno...!  I dont use an extra computed field since whenever you change the keyword the computed field also changes while comparing thats why i am going with the environment variable and it works the way schmad wanted.

Please schmad01 increase the points and grade me an "A" i am tired of begging which i dont want to do it anymore!

Hee Hee Hee... you know i am retiring after this question ?

LOL !!!

Hi Bro Zvo!

Ok, great!!!!  That worked. Now a couple more questions and we'll be done.

1.What would I add to the code for multiple fields?
2.I will increase the points but I want to give them to both of you guys for all your help and input and insight.
How do I do that?

and

3.Can I go get a beer now?
Ok, great!!!!  That worked. Now a couple more questions and we'll be done.

1.What would I add to the code for multiple fields?
2.I will increase the points but I want to give them to both of you guys for all your help and input and insight.
How do I do that?

and

3.Can I go get a beer now?
Well,

1.

For multiple field tracking you should simply increase the environment variables.

One variable for each field.  And write them at the postopen event.

A question arises to me if you would like to track each field with two additional fields or.... any one field among a group of fields when modified can reflect on two fields that are common ?

2.

Why would you want to give pts to Sno ?  Cant you give his share also to me ?  ( Hi Sno ??? This is called stealing pts from friends)

3.

Are you getting a guinness or a Sam Adams ?

Enjoy buddy!
Arun.
I am off for the next 4 days !  Enjoy guys!

-Arun.
track each field with 2 additional fields. Just add one more to the code and I can take it from there for any additional fields.  thanks.
ASKER CERTIFIED SOLUTION
Avatar of Arunkumar
Arunkumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, to prevent Arun from getting his 100K too fast, here's how to split points :
Just post a question in community support forum with a link to this question and ask them to split the points between ArunKumar and Snocross and they'll reduce the points for this question and create a for expert question in the same forum (or let you create the second question).

I see Arun picked up on my hint of using code in QuerySave-event of the form, which I would have started out with :-)
Whatever you do, don't give into Arun's begging :-)
haa haa haa !!!  All i am away is one question !  And this is that one !

I know it and schmad01 may offer even 500 with "A" to congratulate me and deposit points in advance for me to help him in the future.

Schmad01 how about a 500 and grade "A" for this solution ?

I will remember you as long as I am logged on with "EE" !!!

And you will have a permanent place in my heart and thought.  

If you feel bad then give me 500 grade "A" and i will refund you 400 grade "A" how is that for a change hmm ?

LOL ! JM .... LOL !!!

;-)
Arun.
Bye now guys i am off to washington DC to see my GF !
haa haa haa !!!  All i am away is one question !  And this is that one !

I know it and schmad01 may offer even 500 with "A" to congratulate me and deposit points in advance for me to help him in the future.

Schmad01 how about a 500 and grade "A" for this solution ?

I will remember you as long as I am logged on with "EE" !!!

And you will have a permanent place in my heart and thought.  

If you feel bad then give me 500 grade "A" and i will refund you 400 grade "A" how is that for a change hmm ?

LOL ! JM .... LOL !!!

;-)
Arun.
Bye now guys i am off to washington DC to see my GF !
Oh boy a lot happened over night!  Arun, shame on you.  I'm glad schmad finally has a solution though...
Upping points for split.
schmad01

You want to reward points to these experts: Arunkumar 130 points and Snocross 70 points

I reduced the points to 130 and refunded the rest. Please accept one experts comment as an answer and post a 70p question for the other expert with a title like : "Points for xxx" and a body "For your help in  ."

** Mindphaser - Community Support Moderator **
Thank you very much! Excellent Work!
You're welcome.
Hey Sno!

Dont you feel bad for earning points just for chatting with me ?

;-)
Arun.
But Arun, it takes great patience and skill to chat with you.
I am back leaving my girlfriend alone....

:-(

Don't be sad.  You will see her again.  Why do you always meet her in DC?  I thought she lives in India?
She works there on a short assignment.  She visits me every other week and i visit her every other week.  We typically meet everyweek anyways....

:-)
Arun.