Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Creates agreement to be uploaded to DocuSign for customer signature.
- #
- # April 2015 Created by Stuart Gripman
- # Dec 2015 Revised to support FM14 and new Portal architecture.
- # April 2017 Adding support for multiple document types
- #
- # Preparation
- Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
- Perform Script [ Specified: From list ; “Global Error Capture/UserAbort” ; Parameter: ]
- Set Variable [ $Action ; Value: SeedCode_GetScriptParameter ( "Action" ) ]
- Set Variable [ $TemplateID ; Value: SeedCode_GetScriptParameter ( "TemplateID" ) ]
- #
- # Action = "Begin"
- If [ $Action = "Begin" ]
- #
- # set the required data
- Set Field [ Globals_Data::g_DocuSignCustomerName ; JOBS@::z_txt_CustomerFullNameFirstLast ]
- Set Field [ Globals_Data::g_DocuSignCustomerEmail ; Jobs@People_CUSTOMER::Email ]
- Set Field [ Globals_Data::g_DocuSignCompanyName ; Jobs@People_CUSTOMER::CompanyName ]
- Set Field [ Globals_Data::g_DocuSignDeviceType ; Case ( IsEmpty ( JOBS@::Drive_DeviceType ) ; JOBS@::Drive_SourceMediaType ; JOBS@::Drive_DeviceType ) ]
- Set Field [ Globals_Data::g_DocuSignDeviceSN ; Case ( IsEmpty ( JOBS@::Drive_DeviceSerialNumber ) ; JOBS@::Drive_SourceMediaSerialNumber ; JOBS@::Drive_DeviceSerialNumber ) ]
- #
- # open the window and prepare the document
- New Window [ Style: Document ; Name: "Create DocuSign Item" ; Top: Get ( WindowTop ) + 25 ; Left: Get ( WindowLeft ) + 25 ]
- Go to Layout [ “Pop Up Window Jobs DocuSign” (JOBS@) ; Animation: None ]
- Adjust Window [ Resize to Fit ]
- // Set Field [ Globals_Data_VL::g_DocuSignAgreementType ; "Legal Authorization" ]
- #
- Set Field [ JOBS@::_k_SelectedCommunication ; $TemplateID ]
- Set Field [ Globals_Data::g_DocuSignAgreement ; JOBS@DocuSign_Templates::DocuSignTemplateBody ]
- Set Field [ Globals_Data::g_DocuSignFields ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[2] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[3] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[4] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[5] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[6] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[7] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[8] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[9] ; "" ]
- Set Field [ Globals_Data::g_DocuSignFields[10] ; "" ]
- Set Field [ Globals_Data::g_DocuSignAgreementType ; JOBS@DocuSign_Templates::DocuSignTemplateTitle ]
- Perform Script [ Specified: From list ; “__ComMenu DocuSign [Action; TemplateID]” ; Parameter: "Action = Refresh" ]
- Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
- Exit Script [ Text Result: 1 ]
- End If
- #
- #
- # Action = "Refresh"
- If [ $Action = "Refresh" ]
- 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 ]
- // 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 ]
- Refresh Window [ Flush cached join results ]
- Exit Script [ Text Result: 1 ]
- End If
- #
- #
- # Action = "Continue"
- If [ $Action = "Continue" ]
- Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
- #
- # Set Document Title
- 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"; "" ) ) ]
- #
- # Add Fields to template and JSON
- If [ not IsEmpty ( Globals_Data::g_DocuSignFields[1] ) ]
- # Loop through the template field list
- Set Variable [ $rep ; Value: 1 ]
- Set Variable [ $maxReps ; Value: Count(Globals_Data::g_DocuSignFields) ]
- Set Variable [ $$extraFields ; Value: "" ]
- Set Variable [ $$lineItems ; Value: "" ]
- Loop
- Set Variable [ $field ; Value: Globals_Data::g_DocuSignFields[$rep] & ":" ]
- Set Field [ Globals_Data::g_DocuSignAgreement ; Globals_Data::g_DocuSignAgreement & & & $field ]
- # Generate JSON for extra fields
- 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] & ":" ; … ]
- Set Variable [ $$lineItems ; Value: Substitute ( List ( $$lineItems ; $row ) ; ; "," ) ]
- Set Variable [ $rep ; Value: $rep + 1 ]
- Exit Loop If [ $rep > $maxReps ]
- End Loop
- Set Variable [ $JSON ; Value: "textTabs\": [" & $$lineItems & "]" ]
- #
- Set Variable [ $$extraFields ; Value: "\"" & "\\\"" & Substitute ( $JSON ; "\"" ; "\\\"" ) & "\"" ]
- #
- # Add some extra carriage returns
- Set Field [ Globals_Data::g_DocuSignAgreement ; Globals_Data::g_DocuSignAgreement & & & ]
- Commit Records/Requests [ With dialog: Off ]
- // Set Variable [ $$extraFields ; Value: JSONSetElement ( "{}" ; "textTabs" ; $$extrafields ; JSONArray ) ]
- End If
- #
- #
- # make sure all required fields are present - these are template specific
- 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. */ ]
- Show Custom Dialog [ "Information Missing" ; "Required information is missing. Enter valid information into all green fields and try again." ]
- Exit Script [ Text Result: 0 ]
- End If
- #
- # validate the email address
- If [ PatternCount ( SMTPit_VerifyEmailAddress ( "Syntax" ; Globals_Data::g_DocuSignCustomerEmail ); "Verified." ) = 0 ]
- Show Custom Dialog [ "Invalid Email" ; "The email address " & Quote ( Globals_Data::g_DocuSignCustomerEmail ) & " is not valid. Correct th…" ]
- Exit Script [ Text Result: 0 ]
- End If
- #
- # switch to the PDF layout and refresh
- Go to Layout [ “Pop Up Window DocuSign PDF” (JOBS@) ; Animation: None ]
- // Perform Script [ Specified: From list ; “__ComMenu DocuSign [Action; TemplateID]” ; Parameter: "Action = Refresh" ]
- Print Setup [ Restore ; With dialog: Off ]
- Adjust Window [ Resize to Fit ]
- #
- # prep variables for saving the file and creating the URL
- Set Variable [ $customerName ; Value: Globals_Data::g_DocuSignCustomerName ]
- Set Variable [ $customerEmail ; Value: Globals_Data::g_DocuSignCustomerEmail ]
- Set Variable [ $docID ; Value: Int ( Random * 10000 ) ]
- Set Variable [ $docType ; Value: Globals_Data::g_DocuSignAgreementType ]
- Set Variable [ $jobID ; Value: Substitute ( JOBS@::_DS_Job_ID_CompleteID; "/" ; "-" ) ]
- Set Variable [ $jobRecID ; Value: JOBS@::_JobID ]
- Set Variable [ $fileName ; Value: Globals_Data_VL::g_DocuSignAgreementType & " " & $jobID & " " & $docID & ".pdf" ]
- Set Variable [ $exportPath ; Value: Let ( platform = Abs ( Get ( SystemPlatform ) ); Case ( platform = 1; "filemac:"; platform = 2; "filewin:"; "" ) ) & Get ( TemporaryPath ) & $fileName ]
- #
- # save the PDF to the temp folder
- Save Records as PDF [ Restore ; With dialog: Off ; “$exportPath” ; Current record ; Create directories: Off ]
- #
- # Error handling
- If [ Get ( LastError ) ≠ 0 ]
- Show Custom Dialog [ "Error" ; "Unable to save DocuSign PDF to temporary folder. Please try again, and notify your database admini…" ]
- Close Window [ Current Window ]
- Exit Script [ Text Result: 0 ]
- End If
- #
- # hand it off to the helper file on Portal
- # CONTEXT SWITCH
- Close Window [ Name: "Create DocuSign Item" ]
- New Window [ Style: Document ; Name: "docusign helper" ; Left: -10000 ]
- Go to Layout [ “UTIL: Add DocuSign File” (JOBS@DocuSign) ; Animation: None ]
- New Record/Request
- Set Field [ JOBS@DocuSign::_kf_JobID ; $jobID ]
- Set Field [ JOBS@DocuSign::_kf_JobRecID ; $jobRecID ]
- Set Field [ JOBS@DocuSign::documentType ; $docType ]
- Set Field [ JOBS@DocuSign::name ; $customerName ]
- Set Field [ JOBS@DocuSign::email ; $customerEmail ]
- Set Field [ JOBS@DocuSign::fields ; $$extraFields ]
- #
- Set Variable [ $docID ; Value: JOBS@DocuSign::__kp_ID ]
- // #
- # import the PDF from the temporary directory
- Set Variable [ $importPath ; Value: Substitute ( $exportPath ; [ "filemac" ; "imagemac" ] ; [ "filewin" ; "imagewin" ] ) ]
- Go to Field [ JOBS@DocuSign::documentPDF ]
- # --don't use the Insert PDF script step here
- Insert Picture [ “$importPath” ]
- #
- # Error handling
- If [ Get ( LastError ) ≠ 0 ]
- Show Custom Dialog [ "Error" ; "Unable to stage the document file for upload to DocuSign. Please try again and notify your databas…" ]
- Delete Record/Request [ With dialog: Off ]
- Close Window [ Name: "docusign helper" ]
- // Close Window [ Name: "Create DocuSign Item" ]
- Exit Script [ Text Result: 0 ]
- Else
- Close Window [ Name: "docusign helper" ]
- // Close Window [ Name: "Create DocuSign Item" ]
- End If
- // #
- // # PSoS script copies the PDF from the RC to the DocuSign Web directory.
- // # ------Pass the helper record's kp_ID as a param.
- // Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
- // 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 ]
- // Set Variable [ $result ; Value: Get ( ScriptResult ) ]
- // # Add error handling here in case PSoS script result indicates a problem. Any result except "success" means it didn't fly.
- // If [ PatternCount ( Get ( ScriptResult ) ; "success" ) = 0 ]
- // Show Custom Dialog [ "Error" ; "Unable to move DocuSign PDF to web directory. Please notify your database administrator of result:… ]
- // Show Custom Dialog [ "Error" ; $result ]
- // Close Window [ Name: "docusign helper" ]
- // Close Window [ Name: "Create DocuSign Item" ]
- // Exit Script [ Text Result: 0 ]
- // End If
- // #
- // # Hand off to DocuSign
- // 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 ]
- // #
- // # Error handling
- // 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 ]
- // Show Custom Dialog [ "DocuSign Error" ; "DocuSign reported an error. Please try again and notify your database administrator." ]
- // Close Window [ Name: "docusign helper" ]
- // Close Window [ Name: "Create DocuSign Item" ]
- // Exit Script [ Text Result: 0 ]
- // End If
- // #
- #
- # Run docusign process from helper file
- Perform Script [ Specified: From list ; “Launch.Docusign” from file: “DocuSign Helper” ; Parameter: $docID ]
- #
- # Error handling
- #
- // Set Variable [ $envID ; Value: JOBS@DocuSign::envelopeID ]
- Set Variable [ $subject ; Value: "DocuSign " & $docType & " document sent for signature." ]
- Set Variable [ $body ; Value: $docType & " document sent for signature." & "¶File Name: " & $fileName & & & "For more info check the \"Docs\" tab" ]
- Close Window [ Name: "docusign helper" ]
- #
- # create the com log entry
- Select Window [ Name: "Create Docusign Item" ; Current file ]
- Perform Script [ Specified: From list ; “New ComLog Note Auto entry [Context] (Subject; Body)” ; Parameter: "Context = Jobs ; Subject = " & $subject & " ; Body = " & $body ]
- #
- # close process windows and take the user back to the starting layout
- Close Window [ Name: "Create DocuSign Item" ]
- #
- Set Variable [ $confirmMessage ; Value: SDialog_Set( "dialog-timeout" ; 2 ) & SDialog_Set("dialog-min_width" ; 300) & SDialog_InputDialog( TextSize ( "DocuSign Document Sent Successfully" ; 18 ) ) ]
- Exit Script [ Text Result: 1 ]
- #
- // Perform Script [ Specified: From list ; “__ComMenu DocuSign [Action; TemplateID]” ; Parameter: "Action = Finish" ]
- // Exit Script [ Text Result: 1 ]
- #
- End If
- #
- # Action = "Finish"
- // If [ $Action = "Finish" ]
- // End If
- #
- #
- # Action = "Cancel"
- If [ $Action = "Cancel" ]
- Close Window [ Current Window ]
- Commit Records/Requests [ Skip data entry validation ; With dialog: Off ]
- Halt Script
- End If
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement