Advertisement
agir

Untitled

Dec 18th, 2018
1,291
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Creates agreement to be uploaded to DocuSign for customer signature.
  2. #
  3. # April 2015 Created by Stuart Gripman
  4. # Dec 2015 Revised to support FM14 and new Portal architecture.
  5. # April 2017 Adding support for multiple document types
  6. #
  7. # Preparation
  8. Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
  9. Perform Script [ Specified: From list ; “Global Error Capture/UserAbort” ; Parameter:    ]
  10. Set Variable [ $Action ; Value: SeedCode_GetScriptParameter ( "Action" ) ]
  11. Set Variable [ $TemplateID ; Value: SeedCode_GetScriptParameter ( "TemplateID" ) ]
  12. #
  13. # Action = "Begin"
  14. If [ $Action = "Begin" ]
  15. #
  16. # set the required data
  17. Set Field [ Globals_Data::g_DocuSignCustomerName ; JOBS@::z_txt_CustomerFullNameFirstLast ]
  18. Set Field [ Globals_Data::g_DocuSignCustomerEmail ; Jobs@People_CUSTOMER::Email ]
  19. Set Field [ Globals_Data::g_DocuSignCompanyName ; Jobs@People_CUSTOMER::CompanyName ]
  20. Set Field [ Globals_Data::g_DocuSignDeviceType ; Case ( IsEmpty ( JOBS@::Drive_DeviceType ) ; JOBS@::Drive_SourceMediaType ; JOBS@::Drive_DeviceType ) ]
  21. Set Field [ Globals_Data::g_DocuSignDeviceSN ; Case ( IsEmpty ( JOBS@::Drive_DeviceSerialNumber ) ; JOBS@::Drive_SourceMediaSerialNumber ; JOBS@::Drive_DeviceSerialNumber ) ]
  22. #
  23. # open the window and prepare the document
  24. New Window [ Style: Document ; Name: "Create DocuSign Item" ; Top: Get ( WindowTop ) + 25 ; Left: Get ( WindowLeft ) + 25 ]
  25. Go to Layout [ “Pop Up Window Jobs DocuSign” (JOBS@) ; Animation: None ]
  26. Adjust Window [ Resize to Fit ]
  27. // Set Field [ Globals_Data_VL::g_DocuSignAgreementType ; "Legal Authorization" ]
  28. #
  29. Set Field [ JOBS@::_k_SelectedCommunication ; $TemplateID ]
  30. Set Field [ Globals_Data::g_DocuSignAgreement ; JOBS@DocuSign_Templates::DocuSignTemplateBody ]
  31. Set Field [ Globals_Data::g_DocuSignFields ; "" ]
  32. Set Field [ Globals_Data::g_DocuSignFields[2] ; "" ]
  33. Set Field [ Globals_Data::g_DocuSignFields[3] ; "" ]
  34. Set Field [ Globals_Data::g_DocuSignFields[4] ; "" ]
  35. Set Field [ Globals_Data::g_DocuSignFields[5] ; "" ]
  36. Set Field [ Globals_Data::g_DocuSignFields[6] ; "" ]
  37. Set Field [ Globals_Data::g_DocuSignFields[7] ; "" ]
  38. Set Field [ Globals_Data::g_DocuSignFields[8] ; "" ]
  39. Set Field [ Globals_Data::g_DocuSignFields[9] ; "" ]
  40. Set Field [ Globals_Data::g_DocuSignFields[10] ; "" ]
  41. Set Field [ Globals_Data::g_DocuSignAgreementType ; JOBS@DocuSign_Templates::DocuSignTemplateTitle ]
  42. Perform Script [ Specified: From list ; “__ComMenu DocuSign [Action; TemplateID]” ; Parameter: "Action = Refresh" ]
  43. Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
  44. Exit Script [ Text Result: 1 ]
  45. End If
  46. #
  47. #
  48. # Action = "Refresh"
  49. If [ $Action = "Refresh" ]
  50. Set Field [ Globals_Data::g_DocuSignAgreement ; Let ( [   missingMessage = TextColor ( "!!MISSING!!" ; RGB ( 255 ; 50 ; 50 ) );   deviceType = Jobs@Globals_Data::g_DocuSignDeviceType;   deviceSN = Jobs@Globals_Data::g_DocuSignDeviceSN;   custName = Globals_Data::g_DocuSignCustomerName ] ; Substitute (   JOBS@DocuSign_Templates::DocuSignTemplateBody ;   ["<<customer name>>" ; If ( IsEmpty ( custName ); missingMessage; custName ) ];   ["<<device type>>" ; If ( IsEmpty ( deviceType ); missingMessage; deviceType ) ];   ["<<job number>>" ; JOBS@::_DS_Job_ID_CompleteID ];   ["<<price quote>>" ; JOBS@::Job_SelectedPriceQuote ];   ["<<serial number>>" ; If ( IsEmpty ( deviceSN ); missingMessage; deviceSN ) ];   ["<<Alt Minimum>>" ; "$" & 1200 * (1 - JOBS@::Job_DiscountPercent) ];   ["<<Alt Minimum With Discount>>" ; "$" & 1200 * (1 - JOBS@::Job_DiscountPercent) & If ( JOBS@::Job_DiscountPercent > 0; " after your discount" ) ];   ["<<Eval Price With Discount>>";     If(Jobs@Evaluations::ApprovedMin w Discount > 0; "between $" & Jobs@Evaluations::ApprovedMin w Discount & " and ") &    "$" & Jobs@Evaluations::ApprovedMax w Discount &    If( Jobs@Evaluations::ApprovedMax  ≠ Jobs@Evaluations::ApprovedMax w Discount; " after your discount")   ];   [ "<<Selected Target>>";   Let( [     $FileSystem = JOBS@::Target_FileSystem &  " formatted ";     $DriveDetails =If (IsEmpty( JOBS@::z_txt_TargetDriveString ) ;  JOBS@::Target_RecoveryMedia;  JOBS@::z_txt_TargetDriveString & " drive" );     $CustomerTarget = If( PatternCount(JOBS@::Target_MediaSource; "Customer"); " that you provided") ;     $MediaCost =  If(not IsEmpty( JOBS@::Target_EstCostofMedia); " at $" &  JOBS@::Target_EstCostofMedia)];   Case (     PatternCount ( JOBS@::z_txt_TargetDriveString ; "Best Fit" );     $fileSystem & "new drive purchased from DriveSavers that best fits your recovery " & JOBS@::Target_BestFitPriceString;     Substitute ( $FileSystem & $DriveDetails & $CustomerTarget & $MediaCost; ["Target Drive" ; "drive"]; ["@" ; "at"] )     ) // end case   )//end let   ]   )  // end substitute )  // end let  ]
  51. // Set Field [ Globals_Data::g_DocuSignAgreement ; Let ( [   missingMessage = TextColor ( "!!MISSING!!" ; RGB ( 255 ; 50 ; 50 ) );   deviceType = Jobs@Globals_Data::g_DocuSignDeviceType;   deviceSN = Jobs@Globals_Data::g_DocuSignDeviceSN ] ; Substitute (   JOBS@DocuSign_Templates::DocuSignTemplateBody ;   ["<<customer name>>" ; Globals_Data::g_DocuSignCustomerName ];   ["<<device type>>" ; If ( IsEmpty ( deviceType ); missingMessage; deviceType ) ];   ["<<job number>>" ; JOBS@::_DS_Job_ID_CompleteID ];   ["<<serial number>>" ; If ( IsEmpty ( deviceSN ); missingMessage; deviceSN ) ]   )  // end substitute )  // end let  ]
  52. Refresh Window [ Flush cached join results ]
  53. Exit Script [ Text Result: 1 ]
  54. End If
  55. #
  56. #
  57. # Action = "Continue"
  58. If [ $Action = "Continue" ]
  59. Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
  60. #
  61. # Set Document Title
  62. Set Variable [ $$DocTitle ; Value: Let (   theTemplate = JOBS@::_k_SelectedCommunication;   Case (     theTemplate = "D002";     "APPROVAL TO PROCEED WITH RECOVERY ATTEMPT";     theTemplate = "D001";     "LEGAL AUTHORIZATION TO ACCESS DATA";     ""   ) ) ]
  63. #
  64. # Add Fields to template and JSON
  65. If [ not IsEmpty ( Globals_Data::g_DocuSignFields[1] ) ]
  66. #  Loop through the template field list
  67. Set Variable [ $rep ; Value: 1 ]
  68. Set Variable [ $maxReps ; Value: Count(Globals_Data::g_DocuSignFields) ]
  69. Set Variable [ $$extraFields ; Value: "" ]
  70. Set Variable [ $$lineItems ; Value: "" ]
  71. Loop
  72. Set Variable [ $field ; Value: Globals_Data::g_DocuSignFields[$rep] & ":" ]
  73. Set Field [ Globals_Data::g_DocuSignAgreement ; Globals_Data::g_DocuSignAgreement  & & & $field ]
  74. # Generate JSON for extra fields
  75. Set Variable [ $row ; Value: JSONSetElement ("{}" ;     [ "name" ; Globals_Data::g_DocuSignFields[$rep] & ":" ; 1 ] ;     [ "tabLabel" ; Globals_Data::g_DocuSignFields[$rep] ; 1 ] ;     [ "locked" ; "false" ; 1 ] ;     [ "anchorString" ; Globals_Data::g_DocuSignFields[$rep] & ":" ; … ]
  76. Set Variable [ $$lineItems ; Value: Substitute ( List ( $$lineItems ; $row ) ; ; "," ) ]
  77. Set Variable [ $rep ; Value: $rep + 1 ]
  78. Exit Loop If [ $rep > $maxReps ]
  79. End Loop
  80. Set Variable [ $JSON ; Value: "textTabs\": [" & $$lineItems & "]" ]
  81. #
  82. Set Variable [ $$extraFields ; Value: "\"" & "\\\"" & Substitute ( $JSON ; "\"" ; "\\\"" ) & "\"" ]
  83. #
  84. # Add some extra carriage returns
  85. Set Field [ Globals_Data::g_DocuSignAgreement ; Globals_Data::g_DocuSignAgreement  & & & ]
  86. Commit Records/Requests [ With dialog: Off ]
  87. // Set Variable [ $$extraFields ; Value: JSONSetElement ( "{}" ; "textTabs" ; $$extrafields ; JSONArray ) ]
  88. End If
  89. #
  90. #
  91. # make sure all required fields are present - these are template specific
  92. If [ Let ( [   a = IsEmpty ( Globals_Data::g_DocuSignDeviceType );   b = IsEmpty ( Globals_Data::g_DocuSignDeviceSN );   c = IsEmpty ( Globals_Data::g_DocuSignCompanyName );   d = IsEmpty ( Globals_Data::g_DocuSignCustomerEmail );   e = IsEmpty ( Globals_Data::g_DocuSignCustomerName ) ];   Case (     // Legal Authorization     JOBS@::_k_SelectedCommunication = "D001";     a + b + c + d + e > 0;     // Special Approval     JOBS@::_k_SelectedCommunication = "D002";     d + e > 0;     0   ) ) /* This calc is designed to let you check for required fields based on the selected template. Not all templates require all fields. For a given template, add the let variables of the required fields. If that sum is greater than zero, one of the fields is empty and you have a failure state. */ ]
  93. Show Custom Dialog [ "Information Missing" ; "Required information is missing. Enter valid information into all green fields and try again." ]
  94. Exit Script [ Text Result: 0 ]
  95. End If
  96. #
  97. # validate the email address
  98. If [ PatternCount ( SMTPit_VerifyEmailAddress ( "Syntax" ; Globals_Data::g_DocuSignCustomerEmail ); "Verified." ) = 0 ]
  99. Show Custom Dialog [ "Invalid Email" ; "The email address " & Quote ( Globals_Data::g_DocuSignCustomerEmail ) & " is not valid. Correct th…" ]
  100. Exit Script [ Text Result: 0 ]
  101. End If
  102. #
  103. # switch to the PDF layout and refresh
  104. Go to Layout [ “Pop Up Window DocuSign PDF” (JOBS@) ; Animation: None ]
  105. // Perform Script [ Specified: From list ; “__ComMenu DocuSign [Action; TemplateID]” ; Parameter: "Action = Refresh" ]
  106. Print Setup [ Restore ; With dialog: Off ]
  107. Adjust Window [ Resize to Fit ]
  108. #
  109. # prep variables for saving the file and creating the URL
  110. Set Variable [ $customerName ; Value: Globals_Data::g_DocuSignCustomerName ]
  111. Set Variable [ $customerEmail ; Value: Globals_Data::g_DocuSignCustomerEmail ]
  112. Set Variable [ $docID ; Value: Int ( Random * 10000 ) ]
  113. Set Variable [ $docType ; Value: Globals_Data::g_DocuSignAgreementType ]
  114. Set Variable [ $jobID ; Value: Substitute ( JOBS@::_DS_Job_ID_CompleteID; "/" ; "-" ) ]
  115. Set Variable [ $jobRecID ; Value: JOBS@::_JobID ]
  116. Set Variable [ $fileName ; Value: Globals_Data_VL::g_DocuSignAgreementType & " " & $jobID & " " & $docID & ".pdf" ]
  117. Set Variable [ $exportPath ; Value: Let (   platform = Abs ( Get ( SystemPlatform ) );   Case (     platform = 1; "filemac:";     platform = 2; "filewin:";     ""   ) ) & Get ( TemporaryPath ) & $fileName ]
  118. #
  119. # save the PDF to the temp folder
  120. Save Records as PDF [ Restore ; With dialog: Off ; “$exportPath” ; Current record ; Create directories: Off ]
  121. #
  122. # Error handling
  123. If [ Get ( LastError )0 ]
  124. Show Custom Dialog [ "Error" ; "Unable to save DocuSign PDF to temporary folder. Please try again, and notify your database admini…" ]
  125. Close Window [ Current Window ]
  126. Exit Script [ Text Result: 0 ]
  127. End If
  128. #
  129. # hand it off to the helper file on Portal
  130. # CONTEXT SWITCH
  131. Close Window [ Name: "Create DocuSign Item" ]
  132. New Window [ Style: Document ; Name: "docusign helper" ; Left: -10000 ]
  133. Go to Layout [ “UTIL: Add DocuSign File” (JOBS@DocuSign) ; Animation: None ]
  134. New Record/Request
  135. Set Field [ JOBS@DocuSign::_kf_JobID ; $jobID ]
  136. Set Field [ JOBS@DocuSign::_kf_JobRecID ; $jobRecID ]
  137. Set Field [ JOBS@DocuSign::documentType ; $docType ]
  138. Set Field [ JOBS@DocuSign::name ; $customerName ]
  139. Set Field [ JOBS@DocuSign::email ; $customerEmail ]
  140. Set Field [ JOBS@DocuSign::fields ; $$extraFields ]
  141. #
  142. Set Variable [ $docID ; Value: JOBS@DocuSign::__kp_ID ]
  143. // #
  144. # import the PDF from the temporary directory
  145. Set Variable [ $importPath ; Value: Substitute ( $exportPath ; [ "filemac" ; "imagemac" ] ; [ "filewin" ; "imagewin" ] ) ]
  146. Go to Field [ JOBS@DocuSign::documentPDF ]
  147. # --don't use the Insert PDF script step here
  148. Insert Picture [$importPath]
  149. #
  150. # Error handling
  151. If [ Get ( LastError )0 ]
  152. Show Custom Dialog [ "Error" ; "Unable to stage the document file for upload to DocuSign. Please try again and notify your databas…" ]
  153. Delete Record/Request [ With dialog: Off ]
  154. Close Window [ Name: "docusign helper" ]
  155. // Close Window [ Name: "Create DocuSign Item" ]
  156. Exit Script [ Text Result: 0 ]
  157. Else
  158. Close Window [ Name: "docusign helper" ]
  159. // Close Window [ Name: "Create DocuSign Item" ]
  160. End If
  161. // #
  162. // # PSoS script copies the PDF from the RC to the DocuSign Web directory.
  163. // # ------Pass the helper record's kp_ID as a param.
  164. // Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
  165. // Perform Script on Server [ Specified: From list ; “PSoS Move File [kp_ID]” from file: “DocuSign Helper” ; Parameter: JOBS@DocuSign::__kp_ID ; Wait for completion: On ]
  166. // Set Variable [ $result ; Value: Get ( ScriptResult ) ]
  167. // # Add error handling here in case PSoS script result indicates a problem. Any result except "success" means it didn't fly.
  168. // If [ PatternCount ( Get ( ScriptResult ) ; "success" ) = 0 ]
  169. // Show Custom Dialog [ "Error" ; "Unable to move DocuSign PDF to web directory. Please notify your database administrator of result:… ]
  170. // Show Custom Dialog [ "Error" ; $result ]
  171. // Close Window [ Name: "docusign helper" ]
  172. // Close Window [ Name: "Create DocuSign Item" ]
  173. // Exit Script [ Text Result: 0 ]
  174. // End If
  175. // #
  176. // # Hand off to DocuSign
  177. // Insert from URL [ Select ; With dialog: Off ; JOBS@DocuSign::envelopeID ; "httpspost://pacheco.drivesavers.com/docusign_depot/sendToDocusign.php?name=" & $customerName & "&email=" & $customerEmail & "&jobid=" & $jobID & "&docid=" & $docID & "&doctype=" & $docType ]
  178. // #
  179. // # Error handling
  180. // If [ Let (   result = JOBS@DocuSign::envelopeID;   PatternCount ( result ; "error" ) +   PatternCount ( result ; "warning" ) +   PatternCount ( result ; "fail" ) ) // this will have a result of > 0 if any of the terms appear in the envelopeID field ]
  181. // Show Custom Dialog [ "DocuSign Error" ; "DocuSign reported an error. Please try again and notify your database administrator." ]
  182. // Close Window [ Name: "docusign helper" ]
  183. // Close Window [ Name: "Create DocuSign Item" ]
  184. // Exit Script [ Text Result: 0 ]
  185. // End If
  186. // #
  187. #
  188. # Run docusign process from helper file
  189. Perform Script [ Specified: From list ; “Launch.Docusign” from file: “DocuSign Helper” ; Parameter: $docID ]
  190. #
  191. # Error handling
  192. #
  193. // Set Variable [ $envID ; Value: JOBS@DocuSign::envelopeID ]
  194. Set Variable [ $subject ; Value: "DocuSign " & $docType & " document sent for signature." ]
  195. Set Variable [ $body ; Value: $docType & " document sent for signature." & "¶File Name: " & $fileName  & & & "For more info check the \"Docs\" tab" ]
  196. Close Window [ Name: "docusign helper" ]
  197. #
  198. # create the com log entry
  199. Select Window [ Name: "Create Docusign Item" ; Current file ]
  200. Perform Script [ Specified: From list ; “New ComLog Note Auto entry [Context] (Subject; Body)” ; Parameter: "Context = Jobs ; Subject = " & $subject & " ; Body = " & $body ]
  201. #
  202. # close process windows and take the user back to the starting layout
  203. Close Window [ Name: "Create DocuSign Item" ]
  204. #
  205. Set Variable [ $confirmMessage ; Value: SDialog_Set( "dialog-timeout" ; 2 ) & SDialog_Set("dialog-min_width" ; 300) & SDialog_InputDialog( TextSize ( "DocuSign Document Sent Successfully" ; 18 ) ) ]
  206. Exit Script [ Text Result: 1 ]
  207. #
  208. // Perform Script [ Specified: From list ; “__ComMenu DocuSign [Action; TemplateID]” ; Parameter: "Action = Finish" ]
  209. // Exit Script [ Text Result: 1 ]
  210. #
  211. End If
  212. #
  213. # Action = "Finish"
  214. // If [ $Action = "Finish" ]
  215. // End If
  216. #
  217. #
  218. # Action = "Cancel"
  219. If [ $Action = "Cancel" ]
  220. Close Window [ Current Window ]
  221. Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
  222. Halt Script
  223. End If
  224. #
Advertisement
RAW Paste Data Copied
Advertisement