?
Solved

Removing a value from a field in LotusScript

Posted on 2005-05-03
24
Medium Priority
?
1,958 Views
Last Modified: 2013-12-18
I a field in my source document with usernames.  During the queryclose, how can I remove the current users name from the list if it is there

Set doc = Source.Document
get the value from the doc for the field NagList
     if NagList is empty
             do nothing
     else
             need to get current users name
             check to see if the current user is in the value from NagList
             if current user is in the field
                remove the current users name from field
             else
                do nothing
0
Comment
Question by:Jaziar
  • 10
  • 9
  • 4
  • +1
24 Comments
 
LVL 13

Assisted Solution

by:CRAK
CRAK earned 200 total points
ID: 13917807
Don't you need to do that at some point where you are sure that the user intends to save his changes, like QuerySave? (both events support @formula as well)

Field NagList := @Trim(@Replace(NagList; @UserName; ""))

You might have to force a FileCloseWindow that that's about all! In QueryClose you'd still have to trigger FileSave or the change won't be permanent....


Alternatively, in the field's translation or computation:
@Trim(@Replace(NagList; @UserName; ""))


Don't get me wrong, script can't be the problem either, but it'll require more effort....
0
 

Author Comment

by:Jaziar
ID: 13917895
CRAK if I use formula in a action - (Which would be better for me) how would I get the field values from the source document? - I need to get the values from NagList and push back the change values if any.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 13918321
WHen you run it on selected documents , all teh field values are available as the document is the one on which the agent runs, afterwards it's just putting the code what Crak has given

No Points for me

Partha
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Jaziar
ID: 13918449
Here is what I was trying to do - you may have answered the question, but I dont understand yet.

I create a document and send it John and Chuck
My field NagList is populated with John and Chuck when I hit the send action
The send action sends John and Chuck a response form (not a email form).  So when they open the the email they are looking at my response form which creates a response document.  There is a reply button action (right now it only
@SetField("Flag"; "Yes");
@Command([FileSave]);
@Command([FileCloseWindow])

John opens the email and click reply
Can I add formula language to this action that will get the names from NagList (which is not in this form) and remove
John's name from the field?

so then if I opened the source document and looked at the value of NagList - it now has only Chuck
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13918907
Crak had the right idea, change your Reply code to:

@SetField("Flag"; "Yes");
@SetField("NagList";@trim(@Replace(NagList;@username;""));
@Command([FileSave]);
@Command([FileCloseWindow])
0
 

Author Comment

by:Jaziar
ID: 13919719
The Field NagList is not on the the form.  The Field NagList is on the Create Form not the Response Form.

@SetField("NagList";@trim(@Replace(NagList;@username;""));

This Does Not Work.

@SetField"OnSourceDocument"("NagList";@trim(@Replace(NagList;@username;""));

If we could add that and I know that is not correct(making a point) - it would be perfect
0
 

Author Comment

by:Jaziar
ID: 13919923
THis is what I need

Change the response form so that as each response is created, it checks the nag list in the main document, and if the author is listed, removes the author from the list.

I do not know how to check the main document from the response form?
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13920186
Assume you inherit the parent's doc id (@Text(@DocumentUniqueId)) stored in an additional field in the parent document) - a trick on its own probably.
You could use that inherited value in @GetDocField and @SetDocField (with my earlier suggestion in between).

LS -as you earlier tried- could offer another way out, but I'm in a hurry right now.

Any chanche of getting multiple responses generated simultaneously? You'd better prepare for some save conflicts!
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13920255
Use this code instead of the code I previously suggested:

@setdocfield($Ref;"NagList";@trim(@replace(@getdocfield($Ref;"NagList");@username;"")));

Your user will need Editor access to the database that is producing the source document.
0
 

Author Comment

by:Jaziar
ID: 13920267
Any chanche of getting multiple responses generated simultaneously <- That is possible - Yuck

If you can think of a better way to do this - Im in no hurry  - I would rather have it working the right way than have it quickly
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13920290
You shouldn't get save conflicts using the suggestion I provided.
0
 

Author Comment

by:Jaziar
ID: 13920382
@SetField("Flag"; "Yes");
@SetDocField($Ref;"NagList";@Trim(@Replace(@GetDocField($Ref;"NagList");@UserName;"")));
@Command([FileSave]);
@Command([FileCloseWindow])

I got no errors - but it did not remove any names from the NagList field
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13920812
Does NagList contains the fully qualified Notes name (Joe Smith/Corporate/MyDomain) or just a name (Joe Smith)?

If it only contains the name portion, then the code would be:
@SetDocField($Ref;"NagList";@Trim(@Replace(@GetDocField($Ref;"NagList");@Name([CN];@UserName);"")));

Also check to ensure NagList a multi-value field.
0
 

Author Comment

by:Jaziar
ID: 13920831
its like this

CN=Jaziar Mindstrom/OU=Lex/O=Domain
0
 
LVL 2

Accepted Solution

by:
riprowan earned 600 total points
ID: 13920865
Bingo.  Try this:

@SetDocField($Ref;"NagList";@Trim(@Replace(@GetDocField($Ref;"NagList");@Name([CANONICALIZE];@UserName);"")));
0
 

Author Comment

by:Jaziar
ID: 13921096
If there is only one user name in there - it works
If there are multple names in the field - it does not
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13921127
Then the NagList field is not a multi-value field.  Change this to "Allow Multiple Values" field.  Note that you will have to recompute the field on existing document before it will change (documents created when the field was single-value will continue to have a single value field until the field is recomputed).
0
 

Author Comment

by:Jaziar
ID: 13921141
NagList has always been multiple - sorry should have said that up front
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13921194
I still think it isn't :)   If that code works for a multivalue field with only one element, it will work for one with many elements.  The only reason it wouldn't work is because instead of "seeing" multiple elements in the field (one of which is the name to be removed) it sees a big text string.  Double and triple check the contents of the field in the document you are working with.  I am 99% sure that this is a multivalue problem.
0
 

Author Comment

by:Jaziar
ID: 13921612
oops
you are correct - I have now set it to Multi.  But no other documents have been created - so there is no old data to worry with
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13921671
So does it work now?
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13924432
@ReplaceSubString instead of @Replace sould work in both cases (multiple value and concatenated strings).

I do not agree with riprowan's comment "You shouldn't get save conflicts using the suggestion I provided."
Chanches are slim that you'll get save conflicts (unless you're also working with replicas (local / other servers)), but it can't be ruled out.


Last night I remembered a similar thing I wrote once. An application was running on a serverfarm, so I had to deal with replication/save conflicts. It was a survey database, where the names of participants / invitees would be enterd on the main form. The responses would also be stored in as separate document.
Invitees would not choose "create" from the menu, but press a button instead.
It would refuse to fire from local replica's and first search the database to see if that user had already participated. If not, it would compose and save a "response" document (so it would be found the next time) and open it in edit mode. In a document was already found it would open it in edit mode, unless it was finalized. Users could always continue the survey at a later stage.
Author and reader fields would secure the bunch.
The NagList on the main form would be Readers. [Managers] would be authors.
The user would be author on his own response, [Managers] the readers.
With only a small change of users creating responses on a 2nd server in the serverfarm, a tight replication schedule over a 2nd "back-end" LAN between the servers and no simultaneous writes to a single document, it never failed me!
0
 
LVL 2

Expert Comment

by:riprowan
ID: 13926394
> Chanches are slim that you'll get save conflicts (unless you're also working with replicas (local / other servers)),
> but it can't be ruled out.

CRAK - help me understand.  If you're saying that in a multi-server environment, you can get replication conflicts with my suggestion, then you are correct - you can.  But I think I hear you saying something else.

Let's assume a single-server, single database environment with no replicas.  Jaziar creates a document and puts you and I in the NagList.  We both get the document and create our response documents, hitting the button that contains the update code at precisely the same instant.  This would not create a replication conflict.  The server can only process one update to the parent at a time.

The only way to get replication / save conflicts is if you're running a multi-server or replicated environment.  Agree?
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13929264
Makes perfect sense!

I may be a bit hard headed sometimes. Years ago (R4.5 era) I encountered a couple of issues of which I lost most of the details. I choose to adopt different standard approaches for certain situations that may not occur these days. Servers have grown faster, lots of the old "features" got resolved, so the risk of things going wrong on the very same code is now smaller that before, but I still have the same old flags set in my mind to be very carefull doing things like multiple writes to a single document.

Such situations involve e.g. automated sequential numbering of documents. Quite similar to this situation! Putting that to a stress test will eventually get you in trouble, dispite good sense telling you otherwise.
Duplicate numbers have been found (time between reading and writing was obviously too long), replication/save conflicts that we could not explain and -in a different case where we used a lot of @SetProfileField's- even the doc id of a profile documument getting picked up by an agent that was logging all doc id's in an all doc's view!

The code should be safe. I'd probably use it myself to be honest.
Let's just call it paranoia.... Jaziar's NagList won't get long enough to raise a stress test like that!

Congrats on the point!

Jaziar, thanks! And make it do well!  ;-)

C U around!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question