Custom Docusign Button in Skuid using Snippet - CSRF Issue

edited April 23, 2020 in Questions
I have a custom JS button in SF Classic that is used to send documents to Docusign, and I've successfully replicated the button in a Skuid snippet:

var params = arguments[0],
$ = skuid.$; var model = skuid.model.getModel('UltrasoundRecord'); var ClientUltrasound = skuid.model.getModel('UltrasoundRecord').getFirstRow(); //Docusign Options Setup var CRL='Email~'+ ClientUltrasound.Medical_Director_Email__c +';Role~Medical Director;AccessCode~'+ClientUltrasound.Clinic_Ultrasound_Password__c+';FirstName~'+ClientUltrasound.Medical_Director_First_Name__c+';LastName~'+ClientUltrasound.Medical_Director_Last_Name__c; var DST='*******************************'; //Omitted var CEM= ClientUltrasound.Ultrasound_Note_to_MD__c; var CES=ClientUltrasound.Ultrasound_Email_Subject__c; var url = '/apex/dsfs__DocuSign_CreateEnvelope?[SourceID=' + ClientUltrasound.Id + ']&CRL='+CRL+'&DST='+DST+'&CEM='+CEM+'&CES='+CES; console.log('Merged URL: ' + url); window.open(url.text());

The URL merges all the values correctly, however, due to the Docusign Visualforce pages enforcing CSRF...I get this errror on the resulting page:

The link you followed isn’t valid. This page requires a CSRF confirmation token. Report this error to your Salesforce administrator.  
I know how to fix this using { !URLFOR() } in Visualforce/Apex, but I'm at a loss for how to implement it in Skuid/JS. How can I get the correct URL for a CSRF protected Visualforce page in a Skuid snippet?

Appreciate the assist!

Comments

  • Emily DavisEmily Davis ✭✭✭✭
    edited April 23, 2020
    Brad,
    A few things you might try:
    1. Define a function in your Visualforce code via a <script/> tag that uses the URLFOR function, and call it from your snippet. Something like:
    Visualforce code:
    <script>        function customSkuidDocusignRedirect(params) {            var sourceId = params.sourceId,                crl params.crl;                // Additional params...            var url ="{!URLFOR('/apex/dsfs__DocuSign_CreateEnvelope',null,[SourceId=sourceId, crl=crl,...])}";            window.open(url);        } </script> <skuid:page page="MySkuidDocusignPage"/>
    Skuid snippet code:
    // Get all params needed from Skuid models... var params = {sourceId, crl}; // Add additional params here as needed // Call custom redirect function from our VF page if it exists. // Note that this will only run if your Skuid page is placed in a Visualforce page with a customSkuidDocusignRedirect function defined if (!!customSkuidDocusignRedirect) customSkuidDocusignRedirect(params);

    2. Call an Apex invocable method that accepts parameters from your Skuid snippet and does the redirect. Here's a doc on writing Apex invocable methods for your Skuid pages: https://docs.skuid.com/latest/en/skuid/salesforce/apex/apex-invocable-methods.html

    Let me know if one of those options works for you!
    Emily

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!