docusign / native-ios-sdk

A set of official UI components along with programmable client libraries that enable developers to integrate their products with DocuSign’s signature service API on iOS
https://docusign.github.io/native-ios-sdk/documentation/docusignsdk/
Other
28 stars 27 forks source link

Fields not populating into template using Swift sample code #14

Closed mjzandona closed 5 years ago

mjzandona commented 5 years ago

I have followed the instructions to download the example app code, run the pod install, create template in developer sandbox, rename text box fields in Data Labels and use that name in the Swift code tabKey_* variables. After following all of the instructions, the app is successfully built and running on the simulator. However, all the text fields in the template show "Text" and not the data pre populated in the fields for Tom Woods.

simulator

I do see an error in the completionHandler in TemplatesManager.swift for the following call:

presentSendTemplateControllerWithTemplate

error message

I'm wondering if this error is causing the SDK to not properly execute and fill the fields in the call.

iOSSDK-DocuSign commented 5 years ago

Please ensure correct templateId is passed along with the tabData.

template-id

-- Other relevant details --

Variables such as ‘tabKey_address2’ are used to link tabs in template and apply the default value before kicking off the signing ceremony.

Line from swift sample: static let tabKey_address2: String = "Text 526bf465-583e-426f-9671-04dadbb16dbc";

Tabs can be assigned a “Data Label” (tabLabel from API perspective). For e.g. Text 526bf465-583e-426f-9671-04dadbb16dbc is the tabLabel (can be shared by multiple tabs).

Screenshot from DocuSign web with a template loaded and selected tab. tablabel-template

In order to pass a default value for a text-tab, you would need to identify the “Data Label” on the template and template-id, and use that string as the value.

tabData["Text 526bf465-583e-426f-9671-04dadbb16dbc"] = “221 Main St Dallas TX“

^ And this tabData defaults dictionary is used in sample app to invoke following:

        // display template via sdk
        TemplatesManager.sharedInstance.displayTemplateForSignature(templateId: templateId, controller: self, tabData: tabData, recipientData: recipientData, customFields:customFields, onlineSign: false, attachmentUrl: attachmentUrl)
        { (errMsg) in

            // return to client screen
            let vcIndex = self.navigationController?.viewControllers.index(where: { (viewController) -> Bool in
                if let _ = viewController as? ClientViewController {
                    return true
                }
                return false
            })

            let clientVC = self.navigationController?.viewControllers[vcIndex!] as! ClientViewController
            self.navigationController?.popToViewController(clientVC, animated: true)
        }

Which in turn invokes sdk function to trigger the signing ceremony:

    func displayTemplateForSignature(templateId: String, controller: UIViewController, tabData: Dictionary<String, String>, recipientData: Array<DSMRecipientDefault>, customFields:DSMCustomFields?, onlineSign: Bool, attachmentUrl: URL?, completionHandler: @escaping ((UIViewController?, Error?) -> Void))
    {
        // load PDF data
        var pdfData: Data?
        if (attachmentUrl != nil)
        {
            do {
                pdfData = try Data(contentsOf: attachmentUrl!)
            }
            catch {
                NSLog("Error loading PDF data")
            }
        }

        let mDSMEnvelopeDefaults = DSMEnvelopeDefaults()
        mDSMEnvelopeDefaults.recipientDefaults = recipientData.count > 0 ? recipientData : nil
        mDSMEnvelopeDefaults.tabValueDefaults = tabData
        mDSMEnvelopeDefaults.customFields = customFields

        self.mDSMTemplatesManager?.presentSendTemplateControllerWithTemplate(withId: templateId, envelopeDefaults: mDSMEnvelopeDefaults, pdfToInsert: pdfData, insertAtPosition: DSMDocumentInsertAtPosition.end, signingMode: onlineSign ? DSMSigningMode.online : DSMSigningMode.offline, presenting: controller, animated: true, completion: completionHandler)
    }
iOSSDK-DocuSign commented 5 years ago

I do see an error in the completionHandler in TemplatesManager.swift for the following call: presentSendTemplateControllerWithTemplate

Thanks for sharing this detail. Swift sample is out of date and we are planning to update it to 4.2.

Also, the latest branch to use with cocoapods is release/2.1 (https://github.com/docusign/native-ios-sdk/tree/release/2.1). You may now use do pod 'DocuSign' to integrate with cocoapods.

Could you please share the environment details (Xcode, swift & DocuSignSDK version) currently being used.

mjzandona commented 5 years ago

Here are some screen shots showing you what I'm doing. I'm following your examples as far as I can tell.

Template ID passed to SDK: templateID

Template ID in Xcode

templateIdXcode

tabData passed to SDK

tabData

template Data Label example templateInfo

"U.S.A 94107" should be populating in my template, but all I see is "Text"

It keeps sounding like this example is very easy to implement. But it simply isn't working for me. Are there any other steps I could have missed that are preventing this from working properly?

mjzandona commented 5 years ago

Are you using a Powerform or a template? From your screenshot I see a Recipient field which does not exist in my template form when I modify from the developer sandbox. Signer1

iOSSDK-DocuSign commented 5 years ago

This example is using templates.

Here is a sample template AutoInsuranceClaims.json attached.

AutoInsuranceClaims.json.zip

Regarding not seeing the recipient field, it could be because your template only has 1 recipient. For example, you won't see it during edit mode if you use following template.

Screen Shot 2019-03-28 at 10 14 08 AM
mjzandona commented 5 years ago

I'm using DocuSign SDK v2.0, Xcode v10.1, Swift v3.

Can you run the swift example and provide a screenshot of the fields populated with the info from the app? Let me know what version I should be running.

Also, if you have fixed the completion handler in the closure for the TemplateManager (it correctly has Viewcontroller and error as two passing arguments). The DocusignViewController only has "errMsg" in the call to displayTemplateForSignature.

mjzandona commented 5 years ago

I see you made all the fixes/updates in v2.1 Swift example. I will try starting from the beginning with your latest version.

mjzandona commented 5 years ago

I'm having problems installing the new pods

podinstall

Here is my directory structure

directory
iOSSDK-DocuSign commented 5 years ago

Please add pod --version and other details from the console output (top section) of pod install --repo-update.

Also, the latest branch to use with cocoapods is release/2.1 (https://github.com/docusign/native-ios-sdk/tree/release/2.1). You may now use dopod 'DocuSign' to integrate with cocoapods.

mjzandona commented 5 years ago

Ok, got it now. Project builds and executes but still same behavior as in my very first post above. The data from the app does not get populated into the text fields.

Is this user error of the app on my part? I log in fine. Click on Templates to cache my sample template. Then I:

At this point I'm presented my template with blue text boxes that are populated with "Text" instead of the info from the app.

Can you please build the sample app and template and show me a screen shot of the populated template?

mjzandona commented 5 years ago

I will wait for you to prove that the app works for you with a screenshot of a pre-populated template. I'm going in circles.

When I debug the code, the tabData fields are getting properly assigned to the mDSMEnvelopeDefaults instance of the DSMEnvelopeDefaults class. I should be seeing "Tom Wood" get populated into the fullname text field.

code debug
mjzandona commented 5 years ago

I ended up solving this myself. A little disappointed on the support.

I built the obj-c app and found that the template only gets populated properly in the online mode; offline mode does not work.

AlluraFlow

Online Mode

AlluraOnlineFlow

Offline mode

AlluraOfflineFlow

The swift sample app defaults to offline mode. I changed the logic so that it prompts the user to select the mode

SwiftFlowCodeChange

and when I select online, I can get it to work.

swift_working

Why does offline not work???

iOSSDK-DocuSign commented 5 years ago

Hi @mjzandona,

In the screenshots you shared above for online flow, you are using "Home Insurance Claim" template, that has the tab defaults data.

Whereas, in the offline mode, you are using "Auto Insurance Claim". This template showcases signing without tab-defaults, and so it doesn't have tab-defaults assigned during offline.

In offline mode, If you use the same "Home Insurance Claim" template, you would see the tab defaults are also getting applied (exactly same data as online screenshot you shared). Here is the screenshot with swift sample for your reference, and swift sample video linked at the bottom.

Home_insurance_claim_adjuster_template-with-tab-defaults

Please find the the video and other files linked below to help understand the offline tab defaults use-case:

mjzandona commented 5 years ago

The first set of 3 screen shots is from the obj-c sample app. And the only option is to use the auto insurance claim. All the screen shots are using auto insurance. I did not use home insurance template. Now I’m confused. The movie would be helpful but it looks like the file is too big. Can you host it on Dropbox or YouTube?

On Apr 11, 2019, at 11:50 AM, iOSSDK-DocuSign notifications@github.com<mailto:notifications@github.com> wrote:

Hi @mjzandonahttps://github.com/mjzandona,

In the screenshots you shared above for online you are using "Home Insurance Claim" template, that has the tab defaults data.

In the offline mode, you are using "Auto Insurance Claim", that doesn't have tab defaults assigned during offline.

In offline mode, If you use the same "Home Insurance Claim" template, you would see the tab defaults are also getting applied (exactly same data as online screenshot you shared). Here is the screenshot for your reference.

[Home_insurance_claim_adjuster_template-with-tab-defaults][55982817-95af2a00-5c4e-11e9-918c-7e9bd4e8c64a.png]https://user-images.githubusercontent.com/31968825/55982817-95af2a00-5c4e-11e9-918c-7e9bd4e8c64a.png

Please find the the video and other files linked below to help understand the offline tab defaults use-case:

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/docusign/native-ios-sdk/issues/14#issuecomment-482250572, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEUKeFKOM_jZL7vAdNQZQDLCIg2CF-kTks5vf4PYgaJpZM4cMyZv.

mjzandona commented 5 years ago

Your screen shot of "home insurance claim" from the obj-c app is actually the "investment agreement" from the swift sample app. It's like we're talking about different sample apps.

In the insurance app, clicking on home insurance claim does nothing (it's a dummy option). The only option that does anything is the auto insurance option which triggers the sample template provided by you that gets added to my sandbox.

mjzandona commented 5 years ago

Just watched your video. What is different between the Auto Insurance and Home Insurance templates you are selecting in the swift app?

iOSSDK-DocuSign commented 5 years ago

Regarding Objective-C sample:

You should be able to access and use both templates, "Home Insurance" & "Auto Insurance", on Objective-C sample as well with offline.

ObjC-Allura-accessing-both-templates

Please have a look at the video for Offline signing walkthrough with Objective-C based sample app.

In order to access the template in offline mode, user would need to download it first. Once the template has been cached on device for offline use, user may start the offline signing session with additional recipients and/or tab default values. Both samples also show adding an extra PDF documents to append with the template documents during signing.

mjzandona commented 5 years ago

Thanks. More specifically, what is different for each template in your developer sandbox? How is the signer area configured?

recipient

The sample repository has one pdf file that gets uploaded to the developer sandbox to create the template (you are showing two templates in the app: Home and Auto. What is the difference because the same pdf file is being used?

I add the text fields, copy the Data Label "variable" names into the swift code. I assume that is the same for both of your templates.

mjzandona commented 5 years ago

Is there a way to chat and screenshare with you? I think that would simplify all this back and forth. I'm not sure if we're on the same page.

iOSSDK-DocuSign commented 5 years ago

Thanks. More specifically, what is different for each template in your developer sandbox?

Each of the templates contain different configurations (signers, documents, etc). For details on templates, please take a look at the Official DocuSign support page:

How is the signer area configured?

To configure the signer area within Templates: Create Templates.

Is there a way to chat and screenshare with you? I think that would simplify all this back and forth. I'm not sure if we're on the same page.

Yes, It would be great to have someone get in touch with you. Working on getting someone from customer support or developer evangelism team to get help on these matters. Will get in touch with you over email.

The sample repository has one pdf file that gets uploaded to the developer sandbox to create the template (you are showing two templates in the app: Home and Auto. What is the difference because the same pdf file is being used?

"Home Insurance" and "Auto Insurance" are using different PDFs. They look quite similar, but they are different, one has the title "Investment Agreement" and other has "Car Accident Claim" as title.

auto-insurance home-insurance

I add the text fields, copy the Data Label "variable" names into the swift code. I assume that is the same for both of your templates.

You would also need to make sure that Data Labels for both templates match. And correct templateId is used. You would need to edit the Data Labels manually to match (screenshot added in first reply to this issue/thread).

mjzandona commented 5 years ago

Ok thanks.

In your swift movie, your "Home Insurance" template (which is really the Investment Agreement) is the one that works properly in offline mode. If you could show me how your signer area is configured, I can probably figure this out on my own. My problem is that I get various errors in the app when caching depending on how I setup the template signer/host information in the sandbox. This is the only way I can get "in person signer" to work is the following:

recipient

If I change any of the fields I get an error in the app that says:

error

None of this is an issue when I configure my template for online mode. Everything works. The only downside is that you don't support pdf insertion for online mode. Can that feature be requested? What is the reason not to allow adding pdf docs to an envelope in online signing mode?

mjzandona commented 5 years ago

Is it possible I don't have proper permission to use "offline" mode? Why would the same exact template work for online mode (in person signing) but not work for offline mode. Offline mode seems to be a special feature that may require a special license?

I will try to post a video that shows me using the same exact template for online and offline signing. Offline is not populating the information.

iOSSDK-DocuSign commented 5 years ago

Update: "Offline Signing & Templates" are enabled by default to any new developer sandbox account.

Yes. You would need to have offline signing & templates enabled in your account. Getting you in touch with the customer support team.

55997036-32cd8b00-5c6e-11e9-9cce-47c465cf59d2
mjzandona commented 5 years ago

Thank you. It feels like I'm finally getting somewhere.

For my application, I don't require offline signing. But I do need ability to have pdf insert to envelopes.

From the documentation, it looks like pdf insert is ignored for online signing. Why is that the case?

offlinesigning
iOSSDK-DocuSign commented 5 years ago

You're welcome!

From the documentation, it looks like pdf insert is ignored for online signing. Why is that the case?

This is something that's not supported out of the box for online signing.

For v2.x, alternative is to use offline signing flow to create envelopes with templates and add additional pdf with pdfToInsert parameter and proceed with offline signing. Once the signing is complete in offline mode, app/user may sync the envelope back to DocuSign servers when the network is reachable.

Also, sent you a meeting invitation.

iOSSDK-DocuSign commented 5 years ago

Got this resolved on side channel. This is the updated code in swift sample app that

    /**
     Returns Array of the recipient data that will be passed into the template
     */
    func getTemplateRecipientData(templateId:String) -> Array<DSMRecipientDefault>
    {
        // comment out following to fix the recipient default not getting applied to template on an external developer account 
        /*if templateId != ProfileManager.Static.templateIdMomemtumDemo && templateId != ProfileManager.Static.templateIdMomemtumDemoWireTransfer {
            NSLog("Warning: Recipient Data not found for given templateId. Returning empty data.")
            return []
        }*/

        let recipientDatum = DSMRecipientDefault.init()
        // Use recipient roleName (other option to use recipient-id) to find unique recipient in the template
        recipientDatum.recipientRoleName = "claimant-roleName"
        recipientDatum.recipientSelectorType = DSMEnvelopeDefaultsUniqueRecipientSelectorType.recipientRoleName
        recipientDatum.recipientType = DSMRecipientType.inPersonSigner
        // In-person-signer name
        recipientDatum.inPersonSignerName = "Tom Wood"
        // Host name (must match the name on the account) and email
        recipientDatum.recipientName = "docusignsdk user"
        recipientDatum.recipientEmail = "docusignsdk.user@dsxtr.com"
        return [recipientDatum]
    }

Will push this change with upcoming release.

ashokds commented 5 years ago

@mjzandona , closing this as resolved.

pushp1010 commented 3 years ago

@ashokds @iOSSDK-DocuSign Hi Ashok,

I tried building my Swift sample Where I am able to login but when I tried to set Tab data but it does not works for me.

below is the screenshot of the Text Id I am using. I am not sure what I am I doing wrong. based on the Documentation and my knowledge it should work.

I have only one template in my account.

Screenshot 2021-05-04 at 6 30 23 PM

Below is the code snippet:

            print(template.templateId)
            let recipientDatum = DSMRecipientDefault()
            // Use recipient roleName (other option to use recipient-id) to find unique recipient in the template
            recipientDatum.recipientRoleName = "Lead"
            recipientDatum.recipientSelectorType = .recipientRoleName
            recipientDatum.recipientType = .inPersonSigner
            // In-person-signer name
            recipientDatum.inPersonSignerName = "Pushpendra Singh"
            // Host name (must match the name on the account) and email
            recipientDatum.recipientName = "pushpendra singh"
            recipientDatum.recipientEmail = "psinghiosdeveloper@gmail.com"

            let textCustomField = DSMTextCustomField()
            textCustomField.name = "Text 06a6bafd-991f-438c-8df2-2f13dc114609"
            textCustomField.value = "Tom Wood"
            textCustomField.show = true

            let tabData1: [String: String] = ["Text 06a6bafd-991f-438c-8df2-2f13dc114609": "jas"]

            let customFields = DSMCustomFields()
            customFields.textCustomFields = [textCustomField]

            TemplatesManager.sharedInstance.displayTemplateForSignature(templateId: template.templateId, controller: self.viewController!, tabData: tabData1, recipientData: [recipientDatum], customFields: customFields, onlineSign: true, attachmentUrl: nil) { (controller, error) in

                print(controller, error)
            }

I am trying onlineSign It should work. Please put on some light here.

ashokds commented 3 years ago

@pushp1010 , could you please open a new issue and link with this ( https://github.com/docusign/native-ios-sdk/issues/14 )