You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Extracting data from Numbers into a Calendar Event

I am creating a script to bring some data from a Numbers Table into my Calendars in order to quickly create meetings. I have the script working, however I am trying to streamline the process a little more as I keep receiving a small error that I have to dismiss. When the script is trying to read Column J it is receiving the error. I have a pop-up Menu for column J. The answers are either Yes or No. And I have it set to Start with Blank. I want the script to move on to the next row whenever it encounters either a No or that blank that it starts with. I receive the error and once I dismiss it moves on but again trying to avoid the error. The error is because of that Blank. It is not reading the blank correctly. How is the Blank that a pop-up menu read, since I have tried both having the script read as an empty value and also as a Blank. Below is a copy of my script for the Numbers portion. Again I have tried the script reading as "" instead of Blank and still produced the same results.


tell theTable


set rowCount to count rows


-- Start from row 2 to skip headers


if rowCount > 1 then


repeat with j from 2 to rowCount


try


set companyName to value of cell ("B" & j)


set shouldCreateEvent to value of cell ("J" & j) as string


set locationText to value of cell ("C" & j) as text



-- Check if company name exists, if not, end the script


if companyName is missing value or companyName is "" then


display dialog "No company name in row " & j & ". Ending script."


return


end if



-- Skip row if shouldCreateEvent is not set or set to default


if shouldCreateEvent is missing value or shouldCreateEvent is "" or shouldCreateEvent is "Blank" then


-- Optionally log or inform about the skip


-- display dialog "Row " & j & " skipped due to default or empty selection in column J."


nothing -- Continue to the next row


else if shouldCreateEvent is "Yes" then


set eventDescription to "Meeting with " & companyName & " at " & locationText



-- Prompt for date and time for each event


set eventStartDate to my promptForDateTime("Enter the start date and time for the event with " & companyName)


if eventStartDate is missing value then


display dialog "Event creation cancelled or invalid date entered. Skipping this event."


exit repeat


end if


set eventEndDate to eventStartDate + 30 * minutes -- Events are 30 minutes long



my addToCalendar(eventStartDate, eventEndDate, eventDescription, locationText)


else if shouldCreateEvent is not "No" then


display dialog "Unexpected value '" & shouldCreateEvent & "' at row " & j & ", column J, expected 'Yes', 'No', or 'Blank'. Skipping this row."


end if


on error errMsg number errNum


display dialog "Error at row " & j & " when fetching data: " & errMsg & " (Number: " & errNum & ")" buttons {"OK"} default button "OK"


return -- or continue if you want to skip only this row


end try

MacBook Pro 14″

Posted on Oct 17, 2024 10:55 AM

Reply
2 replies

Extracting data from Numbers into a Calendar Event

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.