Using Ninox ChatGPT to create a search
Hi,
My first shot at creating a button to search a field (RTF) to find and mark results. I have a field SEARCH for the search terms and the RTF field is NOTES. The ; on the third line is coming up red underlined and ChatGPT simply can't fix it. Any ideas?
let searchTerm := 'SEARCH';
if searchTerm != null and searchTerm != "" then
let highlightedText := replace(notes, searchTerm, "<mark>" + searchTerm + "</mark>");
'NOTES' := highlightedText;
end;
14 replies
-
You should make the variable 'notes' (no capitals) first so the code can recognize the variabele...
let notes := NOTES;
The field NOTES (with capitals) can then be changed...
-
I am missing something here. Can you advise.
let searchTerm := SEARCH;
let notes := notes;
if searchTerm != null and searchTerm != "" then
let highlightedText := replace(notes, searchTerm, "<mark>" + searchTerm + "</mark>");
notes := highlightedText;
end; -
Hi The error you are getting is to do with the fact that replace() does not work with rich text. You need to wrap the RTF field with raw(). Also, there is no need to assign any variables, so your code can become
if SEARCH != null then NOTES := replace(raw(NOTES), SEARCH, "<mark>" + SEARCH + "</mark>") end
Even the if statement could go if you wish
Regards John
-
Not a problem It might be tricky to catch every use-case but try this
NOTES := replace(raw(NOTES), SEARCH, "<mark>" + SEARCH + "</mark>") NOTES := replace(raw(NOTES), lower(SEARCH), "<mark>" + lower(SEARCH) + "</mark>") NOTES := replace(raw(NOTES), upper(SEARCH), "<mark>" + upper(SEARCH) + "</mark>") NOTES := replace(raw(NOTES), capitalize(SEARCH), "<mark>" + capitalize(SEARCH) + "</mark>")
Content aside
- Status Answered
- 2 mths agoLast active
- 14Replies
- 116Views
-
5
Following