@@ -52,18 +52,18 @@ Set Variable [ $message ; "" ]
5252Set Variable [ $data ; " {}" ]
5353
5454# Send script to server via PSoS
55- If [ Collapsed : OFF ; PatternCount ( Get ( ApplicationVersion ) ; " Server" ) = 0 // if not already running on fmse ]
55+ If [ PatternCount ( Get ( ApplicationVersion ) ; " Server" ) = 0 // if not already running on fmse ]
5656 # Only try to do this if file is hosted
57- If [ Collapsed : OFF ; Get ( ConnectionState ) ≠ 0 ]
57+ If [ Get ( ConnectionState ) ≠ 0 ]
5858 Perform Script on Server [ By name ; ⚠️ PARAMETER " Parameter" NOT PARSED ⚠️ ; Wait for completion : ON ]
5959 Set Variable [ $errorCode ; Get ( LastError ) ]
6060 Set Variable [ $recordId ; JSONGetElement ( Get ( ScriptResult ) ; " data.recordId" ) ]
61- If [ Collapsed : OFF ; $errorCode = 0 and not IsEmpty ( $recordId ) ]
61+ If [ $errorCode = 0 and not IsEmpty ( $recordId ) ]
6262 Enter Find Mode [ Pause : OFF ]
6363 Go to Layout [ Layout : " SaXMLDeliveryExecutionContext" ; Animation : None ]
6464 Set Field [ SaXMLDelivery ::recordId ; $recordId ]
6565 Perform Find
66- Else [ Collapsed : OFF ; Collapsed : OFF ]
66+ Else
6767 Go to Layout [ Layout : " SaXMLDeliveryExecutionContext" ; Animation : None ]
6868 Show All Records
6969 Show Omitted Only
7575# Validate privilege set - must be full access or must have access via the Data API
7676# ■■■■■■■■■■ CONFIGURATION STEP (optional ): Customize restrictions to run this script
7777Set Variable [ $allowedPrivilegeSet ; Get ( AccountPrivilegeSetName ) = " [Full Access]" or not IsEmpty ( FilterValues ( Get ( AccountExtendedPrivileges ) ; " fmrest" ) ) ]
78- If [ Collapsed : OFF ; not $allowedPrivilegeSet ]
78+ If [ not $allowedPrivilegeSet ]
7979 Exit Script [ JSONSetElement ( " " ; [ " errorCode" ; 9 ; JSONNumber ] ; [ " message" ; " Insufficient privileges" ; JSONString ] ) ]
8080End If
8181
@@ -112,13 +112,13 @@ Set Error Capture [ ON ]
112112# =================================================================================================== =
113113
114114# Set up context
115- If [ Collapsed : OFF ; $errorCode = 0 ]
115+ If [ $errorCode = 0 ]
116116 Go to Layout [ Layout : " SaXMLDeliveryExecutionContext" ; Animation : None ]
117117 Set Variable [ $errorCode ; Get ( LastError ) ]
118118End If
119119
120120# Purge old records
121- If [ Collapsed : OFF ; $errorCode = 0 ]
121+ If [ $errorCode = 0 ]
122122 # Delete records older than 3 months
123123 Set Variable [ $purgeDate [1 ] ; Let (
124124 today = Get ( CurrentDate ) ;
@@ -127,25 +127,25 @@ If [ Collapsed: OFF ; $errorCode = 0 ]
127127 Enter Find Mode [ Pause : OFF ]
128128 Set Field [ SaXMLDelivery ::createTimestamp ; " <" & $purgeDate ]
129129 Perform Find
130- If [ Collapsed : OFF ; Get ( FoundCount ) > 0 and Get ( LayoutTableName ) = GetValue ( Substitute ( GetFieldName ( SaXMLDelivery ::xmlFile ) ; " ::" ; ¶ ) ; 1 ) // belt and suspenders ]
130+ If [ Get ( FoundCount ) > 0 and Get ( LayoutTableName ) = GetValue ( Substitute ( GetFieldName ( SaXMLDelivery ::xmlFile ) ; " ::" ; ¶ ) ; 1 ) // belt and suspenders ]
131131 Delete All Records [ With dialog : OFF ]
132132 End If
133133End If
134134
135135# Create new record
136- If [ Collapsed : OFF ; $errorCode = 0 ]
136+ If [ $errorCode = 0 ]
137137 New Record / Request
138138 Set Variable [ $errorCode ; Get ( LastError ) ]
139139End If
140140
141141# Create SaXML xml file on file system
142142# 2024 - 10 - 07 mkos : Added support for $_includeDetailsForAnalysisTools
143- If [ Collapsed : OFF ; $errorCode = 0 ]
143+ If [ $errorCode = 0 ]
144144 Set Variable [ $xmlPath ; Get ( TemporaryPath ) & Get ( FileName ) & " .xml" ]
145145 Set Variable [ $start ; Get ( CurrentTimeUTCMilliseconds ) ]
146- If [ Collapsed : OFF ; $_includeDetailsForAnalysisTools ]
146+ If [ $_includeDetailsForAnalysisTools ]
147147 Save a Copy as XML [ Get ( WindowName ) ; ⚠️ PARAMETER " UniversalPathList" NOT PARSED ⚠️ ; Include details for analysis tools : ON ; Save each layout object & apos ;s binary data under its node : OFF ]
148- Else [ Collapsed : OFF ; Collapsed : OFF ]
148+ Else
149149 Save a Copy as XML [ Get ( WindowName ) ; ⚠️ PARAMETER " UniversalPathList" NOT PARSED ⚠️ ; Include details for analysis tools : OFF ; Save each layout object & apos ;s binary data under its node : OFF ]
150150 End If
151151 Set Variable [ $errorCode ; Get ( LastError ) ]
@@ -155,13 +155,13 @@ End If
155155# Upload xml file to container field
156156# Note , we tried using the Read From Data File step , but it ' s not any faster, and it makes the code more complex, bc you have to read the file in chunks
157157# 2024 - 07 - 17 mkos : Don ' t automatically encode url since ConvertFromFileMakerPath will already do that for us
158- If [ Collapsed : OFF ; $errorCode = 0 ]
158+ If [ $errorCode = 0 ]
159159 Set Variable [ $start ; Get ( CurrentTimeUTCMilliseconds ) ]
160160 Insert from URL [ Verify SSL Certificates : OFF ; Select : ON ; With dialog : OFF ; Target : SaXMLDelivery ::xmlFile ; ⚠️ PARAMETER " URL" NOT PARSED ⚠️ ]
161161 Set Variable [ $errorCode ; Get ( LastError ) ]
162162 Set Variable [ $timeToUpload [1 ] ; GetAsTime ( ( Get ( CurrentTimeUTCMilliseconds ) - $start ) / 1000 ) ]
163163End If
164- If [ Collapsed : OFF ; $errorCode = 0 ]
164+ If [ $errorCode = 0 ]
165165 Set Field [ SaXMLDelivery ::timeToCreate ; $timeToCreate ]
166166 Set Field [ SaXMLDelivery ::timeToUpload ; $timeToUpload ]
167167 Set Field [ SaXMLDelivery ::sizeInBytes ; GetContainerAttribute ( SaXMLDelivery ::xmlFile ; " filesize" ) ]
@@ -171,13 +171,13 @@ If [ Collapsed: OFF ; $errorCode = 0 ]
171171End If
172172
173173# Delete xml file in temp folder
174- If [ Collapsed : OFF ; $errorCode = 0 ]
174+ If [ $errorCode = 0 ]
175175 Delete File [ ⚠️ PARAMETER " UniversalPathList" NOT PARSED ⚠️ ]
176176 Set Variable [ $errorCode ; Get ( LastError ) ]
177177End If
178178
179179# Handle error
180- If [ Collapsed : OFF ; $errorCode > 1 and IsEmpty ( $message ) ]
180+ If [ $errorCode > 1 and IsEmpty ( $message ) ]
181181 Set Variable [ $message [1 ] ; // We would typically use a custom function here, but we wanted this script to have as few dependencies as possible
182182/**
183183 * @SIGNATURE:
@@ -487,7 +487,7 @@ Let ( [
487487
488488) ]
489489End If
490- If [ Collapsed : OFF ; not IsEmpty ( $message )
490+ If [ not IsEmpty ( $message )
491491and PatternCount ( Get ( ApplicationVersion ) ; " Data API Engine" ) = 0
492492and PatternCount ( Get ( ApplicationVersion ) ; " Server" ) = 0 ]
493493 Show Custom Dialog [ Message : $message ; Default Button : " OK" ]
@@ -504,8 +504,8 @@ Set Variable [ $data[1] ; JSONSetElement ( $data
504504Set Variable [ $result [1 ] ; JSONSetElement ( " " ; [ " errorCode" ; $errorCode ; JSONNumber ] ; [ " message" ; $message ; JSONString ] ; [ " data" ; $data ; JSONObject ] ) ]
505505
506506# In case of error , if we were able to get to the layout and create a new record , store $result in the record
507- If [ Collapsed : OFF ; $errorCode > 1 ]
508- If [ Collapsed : OFF ; Get ( LayoutTableName ) = GetValue ( Substitute ( GetFieldName ( SaXMLDelivery ::xmlFile ) ; " ::" ; ¶ ) ; 1 ) and not IsEmpty ( $recordId ) ]
507+ If [ $errorCode > 1 ]
508+ If [ Get ( LayoutTableName ) = GetValue ( Substitute ( GetFieldName ( SaXMLDelivery ::xmlFile ) ; " ::" ; ¶ ) ; 1 ) and not IsEmpty ( $recordId ) ]
509509 Set Field [ SaXMLDelivery ::notes ; Get ( ScriptName ) & " script result:¶" & JSONFormatElements ( $result ) ]
510510 Commit Records / Requests [ Skip data entry validation ; With dialog : OFF ]
511511 End If
@@ -515,9 +515,9 @@ End If
515515# END
516516# =================================================================================================== =
517517
518- If [ Collapsed : OFF ; $parentScriptErrorCaptureState ]
518+ If [ $parentScriptErrorCaptureState ]
519519 Set Error Capture [ OFF ]
520- Else [ Collapsed : OFF ; Collapsed : OFF ]
520+ Else
521521 Set Error Capture [ OFF ]
522522End If
523523
0 commit comments