Simple method to remove files from a listbox - LOTUS 7 - listbox

So I have a button that displays a listbox that I've created. This listbox has some attachments, it is populated with some items ( the attachments ). Also, I created another button which I want to remove the items that I will select from the listbox. Is there any simple method/formula for doing this? Thanks in advance.

Please try to explain a litte bit more clearly what you are trying to do.
I assume that by "listbox" you mean a field of type listbox. That kind of field can not contain attachments, just text values. Do you mean that the listbox contains the name of one or more attachments?
You talk about "a button that displays the listbox". Is that relevant to the problem?
How is the listbox created and populated? I assume from another, field, containing the names of the attachments?
I used some assumptions (you really need to explain your problems in more detail), and this is how I solved it:
Field 'ListData': Text field, hidden. Contains the values you want to display (e.g. names of attachments), separated by semicolon.
Field 'ListBox': Listbox field, allow multiple values, refresh choices on document refresh, use formula for choices:
#Explode(ListData;";")
Button "Delete Selected":
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim selected As Variant
Dim listdata As Variant
Dim files List As String
Dim newlistdata As String
Dim i As Integer
Set uidoc = ws.CurrentDocument
'*** Read the field values and split into arrays
listdata = Split( uidoc.FieldGetText("ListData"), ";" )
selected = Split( uidoc.FieldGetText("ListBox"), ";" )
'*** Convert listdata array into a Lotusscript list
Forall file In listdata
files(file) = file
End Forall
'*** Loop through the array of selected values
For i = 0 To Ubound(selected)
'*** Check if the currently processed value is in the files list
If Iselement(files(selected(i))) Then
Erase files(selected(i)) ' Remove/erase from the list
'*** Add code here to remove attachments from document
'*** if that is what you actually want to do.
'*** Use notesEmbeddedObject.Remove method for that.
End If
Next
'*** Now we have the files list with the selected items removed.
'*** Loop though the list and build a string of remaining values
Forall ff In files
newlistdata = newlistdata + ff + ";"
End Forall
'*** Write the new string of remaining attachments back to the listdata field
Call uidoc.FieldSetText("ListData", newlistdata)
Call uidoc.Refresh
End Sub
You just need to think through the problem and figure out what you really want to do, then break it down to smaller steps, solve each one of those, etc. Lotusscript is not different from other languages in that way,
Note: The code may look complicated and is longer than it has to be, as I added plenty of comments so you (hopefully) can understand what is being done...

1) Use hidden multivalue field for options in listbox. Its value will be computed based on default values (#Attachment or another field value) and will remove all values mentioned in another hidden field "removed" (#Replace).
2) "Removed" field will be populated by your Remove button like
FIELD removed := #Trim(#Unique(removed:listbox));#All
"listbox" contains values currently selected in listbox.
3) I recommend to provide some feedback of removed values and ability to undo/reset.

Related

Delphi - How to filter a ADOTable for strings that contain a substring

noob here. The question once again says it all, :).
I have a ADOTable that is connected to a dbgrid and .mdb file. I want to filter my table field "OwnerName" for all instances of a string that contain another substring and display them on the dbGrid. Each record has this string field "OwnerName". How do I do this?
Ex:
substring: 'J'
Strings: 'Jannie', Johanna, Ko-Ja etc..
If possible I also want to be able to filter for string that not only start with that exact wubstring, but contain it later in as well, as with my stupid example: Ko-Ja.
Regards!!!
The are just two properties you have to set: Filter and Filtered. In the first set the filter condition (similar to SQL) and the second is a boolean stating whether to apply the filter or not.
Example:
YourADOTable.Filter := 'OwnerName LIKE ''%J%''';
YourADOTable.Filtered := True;
The %s in '%J%' means 'anything'.. so this way you are filtering for records which has in the OwnerName the text 'anything followed by a J and then anything again'.
Once you apply the filter, the dbGrid updates automatically.
You can find more info on Filter String at:
http://docwiki.embarcadero.com/Libraries/Sydney/en/Data.DB.TDataSet.Filter

How do i remove rows based on comma-separated list of values in a Power BI parameter in Power Query?

I have a list of data with a title column (among many other columns) and I have a Power BI parameter that has, for example, a value of "a,b,c". What I want to do is loop through the parameter's values and remove any rows that begin with those characters.
For example:
Title
a
b
c
d
Should become
Title
d
This comma separated list could have one value or it could have twenty. I know that I can turn the parameter into a list by using
parameterList = Text.Split(<parameter-name>,",")
but then I am unsure how to continue to use that to filter on. For one value I would just use
#"Filtered Rows" = Table.SelectRows(#"Table", each Text.StartsWith([key], <value-to-filter-on>))
but that only allows one value.
EDIT: I may have worded my original question poorly. The comma separated values in the parameterList can be any number of characters (e.g.: a,abcd,foo,bar) and I want to see if the value in [key] starts with that string of characters.
Try using List.Contains to check whether the starting character is in the parameter list.
each List.Contains(parameterList, Text.Start([key], 1)
Edit: Since you've changed the requirement, try this:
Table.SelectRows(
#"Table",
(C) => not List.AnyTrue(
List.Transform(
parameterList,
each Text.StartsWith(C[key], _)
)
)
)
For each row, this transforms the parameterList into a list of true/false values by checking if the current key starts with each text string in the list. If any are true, then List.AnyTrue returns true and we choose not to select that row.
Since you want to filter out all the values from the parameter, you can use something like:
= Table.SelectRows(#"Changed Type", each List.Contains(Parameter1,Text.Start([Title],1))=false)
Another way to do this would be to create a custom column in the table, which has the first character of title:
= Table.AddColumn(#"Changed Type", "FirstChar", each Text.Start([Title],1))
and then use this field in the filter step:
= Table.SelectRows(#"Added Custom", each List.Contains(Parameter1,[FirstChar])=false)
I tested this with a small sample set and it seems to be running fine. You can test both and see if it helps with the performance. If you are still facing performance issues, it would probably be easier if you can share the pbix file.
This seems to work fairly well:
= List.Select(Source[Title], each Text.Contains(Parameter1,Text.Start(_,1))=false)
Replace Source with the name of your table and Parameter1 with the name of your Parameter.

How to insert key and value dynamically in a property list in eggplant

I have fetched a data as list of list (inner list consists of 2 values e.g., (name,sam)) , now I want to read the data of each inner list and add first data as key and add second data as a value of property list .
e.g.,
((name,sam),(date,fourth),(age,twenty)) = list of lists
convert to = (name:"sam",date:"fourth",age:"twenty") = property list
How can i achieve this ?
set excelRead to WorkBook(ResourcePath(fileName))
set readColumns to excelRead.Worksheet(sheetName)
set listOfData to cellRange("A:B") of readColumns
put (:) into newPlist
repeat with each item of listOfData
put item 1 of it into key
put item 2 of it into Value
end repeat
You just need to put brackets around a variable name to use it as the key in a property list:
put Value into newPlist.(key)
put Value into (key) of newPlist
put Value into newPlist's (key)
It's in the SenseTalk Reference here: Referencing Property List Keys Using Variables

Microsoft Access: Complex string search to update field in another table

I have a table that is linked to Access to return the results of emails into a folder. All of the emails being returned will be answering the same questions. I need to parse this email body text from this table and update several fields of another table with this data. The problem is that the linked table brings the text in super messy. Even though I have the email that is being returned all nicely formatted in a table, it comes back into access a hot mess full of extra spacing. I want to open a recordset based on the linked table (LinkTable), and then parse the LinkTable.Body field somehow so I can update another table with clean data. The data that is coming back into LinkTable looks like this:
Permit? (Note: if yes, provide specific permit type in Additional Requirements section)
No
Phytosanitary Certificate? (Note: if recommended, input No and complete Additional Requirements section)
Yes
Additional Requirements: if not applicable, indicate NA or leave blank (Type of permit required, container labeling, other agency documents, other)
Double containment, The labeling or declaration must provide the following information: -The kind, variety, and origin of each lot of seed -The designation “hybrid” when the lot contains hybrid seed -If the seed was treated, the name of the substance or p
The answer of the first two should either be yes or no, so I figured I could set up code with case statements and based on a match I should place yes or no in the corresponding field in my real table (not sure how to deal with the extra spaces here), The third one could have any number of responses, but it is the last question so anything after the "(Type of permit required, container labeling, other agency documents, other)" could be taken and placed in the other table. Does anyone have any ideas how I could set this up? I am at a bit of a loss, especially with how to deal with all of the extra spaces and how to grab all of the text after the Additional Requirements paragraph. Thank you in advance!
My select statement to get the body text looks like this:
Set rst1 = db.OpenRecordset("SELECT Subject, Contents FROM LinkTable WHERE Subject like '*1710'")
There are multiple ways to do this, one is using Instr() and Len() to find beginning and end of the fixed questions, then Mid() to extract the answers.
But I think using Split() is easier. It's best explained with commented code.
Public Sub TheParsing()
' A string constant that you expect to never come up in the Contents, used as separator for Split()
Const strSeparator = "##||##"
Dim rst1 As Recordset
Dim S As String
Dim arAnswers As Variant
Dim i As Long
S = Nz(rst1!Contents, "")
' Replace all the constant parts (questions) with the separator
S = Replace(S, "Permit? (Note: if yes, provide specific permit type in Additional Requirements section)", strSeparator)
' etc. for the other questions
' Split the remaining string into a 0-based array with the answers
arAnswers = Split(S, strSeparator)
' arAnswers(0) contains everything before the first question (probably ""), ignore that.
' Check that there are 3 answers
If UBound(arAnswers) <> 3 Then
' Houston, we have a problem
Stop
Else
For i = 1 To 3
' Extract each answer
S = arAnswers(i)
' Remove whitespace: CrLf, Tab
S = Replace(S, vbCrLf, "")
S = Replace(S, vbTab, "")
' Trim the remaining string
S = Trim(S)
' Now you have the cleaned up string and can use it
Select Case i
Case 1: strPermit = S
Case 2: strCertificate = S
Case 3: strRequirements = S
End Select
Next i
End If
rst1.MoveNext
' etc
End Sub
This will fail if the constant parts (the questions) have been altered. But so will all other straightforward methods.

XPages repeat from array value field

I have a field which value is an array of strings.
Example: Mom, dad, son, etc.
It is possible to repeat a link with those values?
Example:
Mom
dad
son
And when I click on the link to have a href=www."fieldvalue".com.
EDIT: it is not vector, it is Array.
Create your repeat control. For the value add in your field name. Something like :
document1.getItemValue("myMultiValueField")
I THINK that should repeat your field assuming it is a real multi-value. The comma deliminated string would require more work. So I'm not talking about that...
Make sure the collection name / var name of the repeat is something like "rowData"
rowData should then be a String.
Drop a link control inside the repeat.
Compute the label to be simple "rowData". (no quotes in the code)
Compute the URL - which I THINK is "value" in all properties of the link
That's just javaScript so you should be able to do something like:
return "http://" + rowData + ".com"
That's rough - you'll have to play with it but if I follow you correctly should work.
For a comma deliminated String... in the repeat control you'd need to use SSJS or #functions to break that into an array so the repeat can work on it.
In your repeat you'll need to map the value attribute to the Vector and set a var property, which is how you will reference each element. Note: a comma-separated string is a single value, and a repeat requires multiple values. So you'll need to convert it to a Vector or some other multi-value object.
Within the repeat you can use any other control and compute the value as you would elsewhere. To access each element in your repeat control's source (i.e. each String in your Vector, in this case), use the variable name you've defined in the var property.

Resources