-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSet list item.lua
43 lines (37 loc) · 1.51 KB
/
Set list item.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- Sample entry script for TLex (or tlTerm, tlDatabase etc.) to set a multi-selection list item value on an attribute (F2 style lists, e.g. to tick 'Noun' in a PartOfSpeech multi-selection list)
-- Get document and DTD (document type definition)
local DOC = tApp():GetCurrentDoc();
local DTD = DOC:GetDTD();
local ELEM = DTD:FindElementByName("Entry");
if ELEM == nil then
return "Error: element not found."
end
local ATTR = ELEM:FindAttributeByName("SUBJECT");
if ATTR == nil then
return "Error: attribute not found."
end
local list = DTD:FindListByName("SUBJECT");
local value = "History";
-- Find the list item internal ID via the DTD
local idListItemValue = -1;
if list~=nil then
idListItemValue = list:FindByText(value);
else
return "Error: List item not found."
end
if gCurrentEntry == nil then
return "Error: No current entry."
end
-- If we found the list item ID (if not it's an invalid list item specified above)
if idListItemValue>=0 then
-- If we have entry
if gCurrentEntry~=nil and ATTR~=nil then
-- Note: SetAttributeListID is for single-selection list types ... for multi-selection lists use AddAttributeListID
-- This script could be adapted here for single-selection lists below in future (it can use ATTR type to auto-detect even):
--gCurrentEntry:SetAttributeListID(ATTR, idListItemValue);
if not gCurrentEntry:HasAttributeListID(ATTR, idListItemValue) then
gCurrentEntry:AddAttributeListID(ATTR, idListItemValue);
end
end
end
return ""