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

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

Related

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.

sorting custom objects from array into dictionary by property

Is there an easy way to sort an array of custom objects (in this case Lists) into a dictionary based on a particular property of each list.
[List1, List2, List3, List4, List5];
For example, each List object has an NSString type property, which can be either "MyList","Sent","Received"
How would I create a dictionary based on these properties so that I have a dictionary like so:
"MyList" -> array of lists with MyList as their type property [List1, List5];
"Sent" -> array of lists with Sent as their type property "Received" [List3;
"Received" -> array of lists with Received as their type property [List2, List4];
I'd really rather not loopthrough my entire array of List objects if possible
You need to iterate the array and build your dictionary. If the key isn't already there, create the array and add it to the dictionary, then add the new item to it.
You could alternately use predicates to filter the array into sub-arrays and build the dictionary like that but it's a similar amount of code (for a few options) and doesn't support automatic future expansion when you have another value for the key you're organising on.

Simple method to remove files from a listbox - LOTUS 7

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.

Create and iterate through an array in Velocity Template Language

How to create an array in VTL and add contents to the array? Also how to retrieve the contents of the array by index?
According to Apache Velocity User Guide, right hand side of assignments can be of type
Variable reference
List item
String literal
Property reference
Method reference
Number literal
ArrayList
Map
You can create an empty list, which would satisfy all your needs for an array, in an Apache Velocity template with an expression like:
#set($foo = [])
or initialize values:
#set($foo = [42, "a string", 21, $myVar])
then, add elements using the Java add method:
$foo.add(53);
$foo.add("another string");
but beware, as the Java .add() method for the list type returns a boolean value, when you add an element to the list, Velocity will print, for instance, "true" or "false" based on the result of the "add" function.
A simple work around is assigning the result of the add function to a variable:
#set($bar = $foo.add(42))
You can access the elements of the list using index numbers:
<span>$foo[1]</span>
Expression above would show a span with the text "a string". However the safest way to access elements of a list is using foreach loops.
Creating an array is easy:
#set($array = [])
Putting an element into an array is also easy:
$array.add(23)
Getting an element from an array depends from your Velocity version.
In Velocity 1.6 you must use
$array.get($index)
Since Velocity 1.7 you can use the classic form:
$array[$index]
I haven't created an array in VTL but passed arrays to VTL context and used them. In VTL, you can not retrieve array contents by index, you only use foreach, as example this code is copied from my Dynamic SQL generation VTL Script:
#foreach( $col in $Columns ) SUM($col.DBColumn) AS ''$col.Name''#if($velocityCount!=$Columns.Count), #end #end
For this reason, we also can not have 2D arrays. When I needed an array to store 2 objects in a row, I used the workaround of defining a new class, and putting objects of that class in the single dimensional array.

Trouble adding item to a list with a lookup value

I am adding a new item to a list in SharePoint 2007. One of the columns is a lookup into another list. Here is the code:
li["LOOKUP"] = new SPFieldLookupValue(1,VALUE);
The entry in the list isn't correct and is always using the first value in the other list. When I look at the value of li["LOOKUP"] in the debugger all I get is "1".
VALUE is in the other list and it is the first column.
When adding items to a list only the id of the element from the list being looked up needs to be provided. It was always adding the first element because I always passed in "1". The following code looks up the value and then gets its id and passed this to the field:
SPListItemCollection lookup = LIST.GetItems(qry);
li["LOOKUP"] = lookup[0][SPBuiltInFieldId.ID].ToString();

Resources