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();
Related
I have two lists,
List first = [{'name':'ABC','serialNumber':'ABC-124-353'},
{'name':'XYZ','serialNumber':'XYZ-123-567'},
{'name':'GRE', 'serialNumber': 'GRE-290-128'}];
List second = [{'name':'PQR','serialNumber':'PQR-D123-SII23'},{'name':'GAR','serialNumber':'GAR-G43-432'},
{'name':'MNOP','serialNumber':'XYZ-123-567'}];
Is there any easier way to compare first list and second list by serialNumber.
such that element from first list that doesn't exist in second list are outputted as a result.
So in this case
[{'name':'ABC','serialNumber':'ABC-124-353'},{'name':'GRE', 'serialNumber': 'GRE-290-128'}]
from first list is desired output, because ABC-124-353 and GRE-290-128 doesn't exist in list second
Another solution would be to use where on your first List to check if the serialNumber is contained in the second list:
final secondSerials = second.map((item) => item['serialNumber']).toSet();
print(first.where((item) => !secondSerials.contains(item['serialNumber'])).toList());
I'd make a set of the serial numbers of the second list, so that you can do efficient contains checks.
So:
var secondListSerials = {for (var entry in secondList) entry["serialNumber"]};
var firstListOnly = [for (var entry in firstList)
if (!secondListSerials.contains(entry["serialNumber"]) entry
];
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.
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
I'm looking for a way to append new ListItem to particular list in Google Docs API.
My problem is that I can't figure out how to determine last item in list, so I could just insert new item using it's index.
My vision of how to implement this looks like:
body.insertListItem(body.getChildIndex(lastItem) + 1, newItem);
P.S. Am I doing something wrong, maybe there is some other way to implement appending?
Thanks in advance!
A ListItem is a Paragraph that is associated with a list ID. A ListItem may contain Equation, Footnote, HorizontalRule, InlineDrawing, InlineImage, PageBreak, and Text elements. For more information on document structure, see the guide to extending Google Docs.
ListItems with the same list ID belong to the same list and are numbered accordingly. The ListItems for a given list are not required to be adjacent in the document or even have the same parent element. Two items belonging to the same list may exist anywhere in the document while maintaining consecutive numbering, as the following example illustrates:
var body = DocumentApp.getActiveDocument().getBody();
// Append a new list item to the body.
var item1 = body.appendListItem('Item 1');
// Log the new list item's list ID.
Logger.log(item1.getListId());
// Append a table after the list item.
body.appendTable([
['Cell 1', 'Cell 2']
]);
// Append a second list item with the same list ID. The two items are treated as the same list,
// despite not being consecutive.
var item2 = body.appendListItem('Item 2');
item2.setListId(item1);
I have this code
<c:forEach var="l" value="${logs}">
...
</c:forEach>
and it says:
Attribute value invalid for tag forEach according to TLD
The forEach tag does not support the value attribute. I.e. the <c:forEach value> is not recognized. Really, that's basically what the error is trying to tell you.
If you consult the documentation of the forEach tag, then you'll see that the value attribute is indeed not mentioned in the attributes table. Only the following attributes are listed:
items - Collection of items to iterate over.
begin - If items specified: Iteration begins at the item located at the specified index. First item of the collection has index 0. If items not specified: Iteration begins with index set at the value specified.
end - If items specified: Iteration ends at the item located at the specified index (inclusive). If items not specified: Iteration ends when index reaches the value specified.
step - Iteration will only process every step items of the collection, starting with the first one.
var - Name of the exported scoped variable for the current item of the iteration. This scoped variable has nested visibility. Its type depends on the object of the underlying collection.
varStatus - Name of the exported scoped variable for the status of the iteration. Object exported is of type javax.servlet.jsp.jstl.core.LoopTagStatus. This scoped variable has nested visibility.
Guess which one you actually need. In case you're unsure, the Java EE tutorial may help.