talk2bks | Posts: 34

Send File not in Static Resources

0 votes

I am getting an error error.validation.sendPackage.noApprovals from the Salesforce Package. 

There's plenty of customization on the Apex class and everything works as long as the file is in the Static Resources. However, when I try to upload a file associated with a record, this is the error that I'm getting. For troubleshooting, I'm including an ID of the record I'm pulling the file from in the initial query. 

ContentDocumentLink cdl = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = 'a1FDK000001DLRc2AO'];
String fileID = cdl.ContentDocumentId;
ContentVersion file = [SELECT Title, VersionData FROM ContentVersion WHERE IsLatest = TRUE and ContentDocumentId=:fileID];

Map doc = new Map();
doc.put('Sample Document', file.VersionData);

 


Approved Answer
Duo_Liang | Posts: 3776

Reply to: Send File not in Static Resources

0 votes

Hi talk2bks,

 

Thanks for your post!

The Apex code of reading blob from ContentVersion file looks good to me. I have a similar setup in my dev environment which works for me:

 

            ContentVersion sr = [SELECT Id, Title,VersionData  FROM ContentVersion WHERE Title = 'Sample PDF' AND IsLatest = TRUE LIMIT 1];

            Map<String,Blob> doc = new Map<String,Blob>();
            doc.put('document1', sr.VersionData);
            
            OneSpanAPIObjects.Document document1 = new OneSpanAPIObjects.Document();
            document1.name = 'document1';
            document1.id = 'document1';
            document1.extract = true;  

            ......
              
            String resp = sdk.createDocuments(packageId, document1, doc);

 

I think the issue is more around how you placed the signatures and fields. Quick question - is this the same file for StaticResource and ContentVersion? If you have document.extract=true;, it's very likely that it only works with certain text anchors/tags/PDF forms.

 

Duo

 

 


talk2bks | Posts: 34

Reply to: Send File not in Static Resources

0 votes

Thanks Duo,

It does appear to the template I was sending up. Can I send up a Word Doc, or does it have to be a PDF?

If I can pass a word doc, can I pass variables to the word doc? I see where I can with a PDF.

The document is a letter for the client to sign. I can change it to a PDF but this is constantly being updated and wanted to be able to update it a lot.


talk2bks | Posts: 34

Reply to: Send File not in Static Resources

0 votes

Oh wait, 

The status of the package was sent as "Sent". The test word doc I was sending up didn't have any signature tags in it yet which was causing the error. I found all these packages in the drafts folder. 

Question: can I send variables to a word doc? I do see where I can with a PDF. To clarify, I want to start the letter with "HI James, ...." in which James is inserted and not some text field.


Duo_Liang | Posts: 3776

Reply to: Send File not in Static Resources

0 votes

Hi there,

 

Text tags and text anchors work with word file.

Text tags is a completely automated extraction method, while text anchors allow you to use the existing words as the anchor and pass in field values via Apex code.

 

Duo


talk2bks | Posts: 34

Reply to: Send File not in Static Resources

0 votes

Thanks for your help.

What I'm trying to accomplish is to use MS Word and insert a small amount of data from Salesforce. I am successful in inserting text using PDF but is there a way to use a Word document? 

Injecting Field Values | OneSpan Community Platform

As of now, it appears that I'm using a "Label" but I can't find any example of using it online and it's not pulling over the data.

------- Class ------

OneSpanAPIObjects.Field field1 = new OneSpanAPIObjects.Field();
field1.name = 'Text1';
field1.value = '200 E MAIN ST, PHOENIX AZ, 85123 USA';

OneSpanAPIObjects.Data data_x = new OneSpanAPIObjects.Data();
document.data = data_x;
document.fields = new List<OneSpanAPIObjects.Field>{field1};
sdk.createDocuments(packageId, document, doc);
pkg.status = OneSpanAPIObjects.PackageStatus.DRAFT;
sdk.updatePackage(pkg, packageId);

------- IN PDF ------

field name "Text1" - this works just fine.

------ IN WORD -----

{{esl_Text1:Signer1:Label}}       //This is the current extraction text. It does create a Label box but does not include the text in there (according to the preview).

 

 


Duo_Liang | Posts: 3776

Reply to: Send File not in Static Resources

0 votes

Hi Brian,

 

If you choose to use text tags, try to upload the document and update the label field value in two step:

        public static void test230630(){
            
            OneSpanSDK sdk = new OneSpanSDK();
        
            OneSpanAPIObjects.Package_x pkg = new OneSpanAPIObjects.Package_x();
            pkg.name = 'Test Transaction Using Apex - ' + Datetime.now().format();

            String roleId1 = 'Signer1';
            OneSpanAPIObjects.Role role1 = new OneSpanAPIObjects.Role();
            role1.signers = sdk.createRolesSigner('John', 'Smith', '[email protected]', 'CEO', 'ABC Bank');
            role1.id = roleId1;
            role1.name = roleId1;
            pkg.roles = new List<OneSpanAPIObjects.Role>{role1};    //add role

            String packageId = sdk.createPackage(pkg);
            System.debug('PackageId: ' + packageId);
 

            //STEP1: Upload Document
            ContentVersion sr = [SELECT Id, Title,VersionData  FROM ContentVersion WHERE Title = 'Example Text Tags' AND IsLatest = TRUE LIMIT 1];

            Map<String,Blob> doc = new Map<String,Blob>();
            doc.put('document1', sr.VersionData);
            
            OneSpanAPIObjects.Document document1 = new OneSpanAPIObjects.Document();
            document1.name = 'document1';
            document1.id = 'document1';
            
            String resp = sdk.createDocuments(packageId, document1, doc);
            
            

            //STEP2: Update Field Value
            OneSpanAPIObjects.Package_x created_pkg = sdk.getPackage(packageId); 
        
            for(OneSpanAPIObjects.Document document: created_pkg.documents)
            {
            
                if(document.Id == 'document1'){
                  for(OneSpanAPIObjects.Approval approval: document.approvals)
                  { 
                      if(approval.Id == 'Signature1'){
                          for(OneSpanAPIObjects.Field field: approval.fields)
                          { 
                              if(field.Id == 'Text1'){
                                  field.value = '200 E MAIN ST, PHOENIX AZ, 85123 USA';
                                  sdk.updateField(packageId, document.Id, approval.Id, field.Id, field);
                              }
                          }
                      }
                  
                  }  
                }  
            }
            
            
            pkg.status = OneSpanAPIObjects.PackageStatus.SENT;
            sdk.updatePackage(pkg, packageId);
            
        
        }

 

Let me know how this works for you.

Duo


Attachments

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off