Solved

Deleting Name from Field

Posted on 2007-11-14
9
183 Views
Last Modified: 2013-12-18
I have a multi-value text field on documents that hold common user names.  I need to provide a view action where a user can select documents and it will cycle though the docs and cycle through the names in the field and remove theirs if it matches their session.CommonUserName.  I have not done much with lists or arrays so I don't know the best approach for testing for the presence of their session.CommonName in the list and removing it.  I have no problem building the collection and cycling though the documents.  I just need help with testing for the presence of the sesssion.CommonUserName in the field and removing it from the list.
0
Comment
Question by:ccarlson62
  • 5
  • 3
9 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 20283826
You don't need LotusScript for this, generally formmula language is better suited here. Create an agent with the ofllowing formula:

SELECT @All;
namesField := name_of_field_you_are_working_on_no_quotes;
@Trim(
  @Replace(
    namesField;
    @UserName;
    NULL_STRING
  )
)
0
 

Author Comment

by:ccarlson62
ID: 20284223
That would be fine only I need the code to execute in all selected docs and I have to prompt them to make sure that they want to actually remove their name.  If I do it in formula, the prompt will show for every doc the code executes against and that would be bad.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20284473
Create 2 agents:

One agent prompts the user and calls the second one if the user clicks OK.

The second one does the work on the selected documents.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 31

Expert Comment

by:qwaletee
ID: 20285884
Or, an agent and an action button in the view that prompts user then runs agent.

If you must have a single script, this shoudl do it. I coded it so t hat you cannot remove your name if it is the only name in the list.


Const fieldName = "Name of the field"
If MsgBox("Remove your name from selected documents?", 292 , "Confirm") = 7 Then Beep : End
Dim s As New NotesSession, db as NotesDatabase, docs as notesDocumentCollection, doc as notesDocument, content as variant, i as Integer, user as string
user = s.CommonUserName
Set db = s.currentDatabase
Set docs = db.unprocessedDocuments
Set doc = docs.getFirstDocument
Do Until doc Is Nothing
  content = doc.getFirstItem(fieldName)
  If Ubound(content) > 0 Then 'skip it if there is only one name -- we don't want to remove the last owner!!!
    For i = 0 to Ubound(content)
      If content(i) = user Then
        content(i) = content(Ubound(content))
                      'puts the last owner in the list in our spot (if we are last, this does nothing)
        Redim Preserve content(Ubound(content)-1)
                      'then drops the last item which is either now a dup or was us anyway
        doc.replaceItemValue fieldName, content
      End If
    Next
  End If
  Set doc = docs.getNextDocument(doc)
Loop
Msgbox "Complete"

Open in new window

0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20285912
Should really have one correction. Between lines 17 and 18, should really have the two more lines
       doc.replaceItemValue fieldName, content
       doc.Save False , False '<--------new line
       Exit For '<--------new line
     End If
 
So basically, I'm assigning the contents to a temp variable content, and searching through the content array element by element.
 
If the name is present, I'm just truncating the content by one (after moving the trunctaed entry to where the current user's name is), then reassing the field value, saving, and letting it drop through to the next document.
 
If not for the exit for, the loop would continue processing, and would puke when it hit the index for the previous upper bound, because the new upper bound is one short, and I'm out of bounds.

Open in new window

0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20285932
Boy this new code snippet thing sucks.  If you paste it directly into the code editor, or even any regular text editor, it comes through as a single line.  Hint: Paste it into a Notes memo first, then cut and paste it from the memo into the editor.
0
 

Author Comment

by:ccarlson62
ID: 20290402
Ok I tried the formula route.  Below is the code in my agent.  Everything is working except the ...
(@Replace(ReviewerProp;sName;NULL_STRING));

Can anyone see whats wrong here?

Select @All;
FIELD audittrail := audittrail;
sName:=@Name([CN];@UserName);
newauditstring := @Text(@Now) +" -  Updated by "+ sName +", Removed self as reviewer";
@Prompt([Ok];"INPUT";"User is "+sname);
@Prompt([Ok];"INPUT";"names are "+ReviewerProp);
@If(@Contains(ReviewerProp;sName);
@Do(@Trim(@Replace(ReviewerProp;sName;NULL_STRING));
@Prompt([Ok];"Message";"should be gone now");
@Prompt([Ok];"Message";"names are "+ReviewerProp);
@SetField("audittrail";newauditstring +@NewLine+ audittrail);
@Command([FileSave]));@Prompt([Ok];"Message";"No Match found"))
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 150 total points
ID: 20291764
You calculate the value but you don't assign it to anything!

You also should not have a [FileSave] at the view level, that's only appropriate in documents in edit mode.

Finally, rather than having an @If around everything, you could just apply the SELECT so that it doesn't actually touch the documents if there is no match.
sName:=@Name([CN];@UserName);
SELECT @Contains(ReviewerProp;sName);
 
@Prompt([Ok];"INPUT: User is "+sname; "names are "+@Implode(ReviewerProp;"; "));
FIELD ReviewerProp := @Replace(ReviewerProp;sName;NULL_STRING);
@Prompt([Ok];"Message: should be gone now"; "names are " + @Implode(ReviewerProp; "; ");
newauditstring := @Text(@Now) +" -  Updated by "+ sName +", Removed self as reviewer";
FIELD audittrail := newauditstring +@NewLine+ audittrail;

Open in new window

0
 

Author Comment

by:ccarlson62
ID: 20291981
Thank you sir!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 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