Outlook API or Applescript not behaving as expected

I have a script for outlook that used to work. It is a stay open script. part of the script caches outlook messages. If there is a change in the outlook folder it makes a brand new cache, else it adds message info (subject, message id, time received) as lists in a record holding also folder ID and lates update
anyway, now I get a fault in this line:

if earliestNonCacheMsgid as integer = item 1 of messageIds of cacheItem as integer then
					set makeNewCache to false

when this executed next time after

set beginning of messageIds of cacheItem to id of messages 1 thru (numOfMsg - cacheSize) in folder id theid

I have tested and for some reason the item 1 of messageIds of cacheItem is a list. There is no problem if the latter statement only result in a single message, but if more messages has arrived then item 1 of messageIds of cacheItem is a list. This has worked before (sort of a year ago), but now it fails. So why is now a list added as an item to a list instead of just adding the new items to the list?

Any ideas?
MacOS: 14.2
AppleScript 2.8 version 2.11

full handler below

on updateCache()
	repeat with cacheItem in cache
		set theid to olFolderId of cacheItem
		set cacheSize to count of messageIds of cacheItem
		--	log "num of cacheitems are: " & cacheSize
		set noUpdate to false
		if cacheSize = 0 then
			set makeNewCache to true
		else
			tell application "Microsoft Outlook" to set numOfMsg to count of messages in folder id theid
			if numOfMsg = 0 then
				set cacheItem to {olFolderId:theid, messageIds:{}, subjects:{}, msgTimes:{}, latestUpdate:(current date)}
				set noUpdate to true
			end if
			-- check if fullblown cache for the folder is needed
			if cacheSize = numOfMsg then
				set noUpdate to true
			else if cacheSize > numOfMsg then
				set makeNewCache to true
			else
				tell application "Microsoft Outlook"
					set earliestNonCacheMsgid to id of message (numOfMsg - cacheSize + 1) in folder id theid
				end tell
				if earliestNonCacheMsgid as integer = item 1 of messageIds of cacheItem as integer then
					set makeNewCache to false
				else
					set makeNewCache to true
				end if
			end if
		end if
		if not noUpdate then
			set tmptimes to {}
			set tmptimes2 to {}
			tell application "Microsoft Outlook"
				if makeNewCache then
					--	log "make new cache"
					set subjects of cacheItem to subject of every message in folder id theid
					set messageIds of cacheItem to id of every message in folder id theid
					set msgTimes of cacheItem to time received of every message in folder id theid
				else
					--	log "update cache with new items, numOfMsg=" & numOfMsg & " cacheSize=" & cacheSize
					set beginning of subjects of cacheItem to subject of messages 1 thru (numOfMsg - cacheSize) in folder id theid
					set beginning of messageIds of cacheItem to id of messages 1 thru (numOfMsg - cacheSize) in folder id theid
					set beginning of msgTimes of cacheItem to time received of messages 1 thru (numOfMsg - cacheSize) in folder id theid
				end if
				set latestUpdate of cacheItem to (current date)
			end tell
		end if
	end repeat
end updateCache

It would be nice if you gave the full script so we can try to run it.

Also when you say you get an error, what does the error say?

And, what mode is Outlook running in? new or legacy?

1 Like