Downloads
GitHub: Generate a PDF with an Omniscript
Overview
This post is about how to generate a PDF with an Omniscript. This example gets opportunity name and displays it in a document which is stored in the opportunity record.
Steps
Step 1. Create Dataraptor to extract information
Step 2. Create Dataraptor to transform extracted information into Vlocity Document template format
Step 3. Create Vlocity Document template
Step 4. Create Omniscript
Step 1. Create Dataraptor to extract information
Open ‘Vlocity DataRaptor Designer’ tab and click on ‘New’ button. Fill the fields with the following values and click on ‘Save’.
Click on the ‘Extract’ tab and get the Opportunity object filtered by ‘opportunityId’.
Click on ‘Output’ tab and get the opportunity id and the name fields.
Step 2. Create Dataraptor to transform extracted information into Vlocity Document template format
Open ‘Vlocity DataRaptor Designer’ tab and click on ‘New’ button. Fill the fields with the following values and click on ‘Save’.
Click on the ‘Transform’ tab and set the opportunity name. (NOTE: do NOT include ‘:‘ in the output variable name because it will be not displayed in the vlocity template document).
Step 3. Create Vlocity Document template
Open ‘Vlocity Document Template’ tab and click on ‘New’ button. Fill the fields with the following values. The ‘Mapping Dataraptor Bundle Name’ field is the dataraptor which was created above.
Click on ‘Edit Section’ button and create a context section. Select ‘Add New Section -> ‘Context’.
The section is called ‘Example’. Fill the ‘Section Content’ with the value Opportunity name: %%OpportunityName%% and click on ‘Save Section’ button. In vlocity template documents, the variables names are added between percentage symbols. For instance: %%myVariableName%%.
Click on ‘Activate’ button.
Step 4. Create Omniscript
Open ‘Vlocity OmniScript Designer’ tab and click on ‘New’ button. Fill the fields with the following values and click on ‘Save’.
Go to ‘CUSTOM HTML TEMPLATES’ section in the script configuration and copy and paste this script.
Drag and drop a ‘Set Values’ action. Create a variable called ‘opportunityId’ and add an opportunity id to test.
Drag and drop a ‘Set Values’ action. Define the following values:
- documentName: document name when you download it.
- documentParentId: record id will be linked the document to get the information. In this example, it is the ‘opportunityId’ set previously.
- templateId: vlocity document template Id.
Drag and drop a ‘DataRaptor Extract Action’ action. Set ‘DataRaptor Interface’ field as ‘POC: Get Opportunity information’ and create one row in the input parameters. Set ‘Data Source’ and ‘Filter Value’ fields as ‘opportunityId’.
Drag and drop a ‘Remote Action’ action. Call the apex class which will create the document. Fill the fields with the following values:
- Remote Class: ObjectDocumentService
- Remote Method: createObjectDocument
- Remote Options:
- input: %Opportunity%
- templateId: %templateId%
Drag and drop a ‘Step’ group.
Drag and drop a ‘Input Block’. The ‘HTML Template Id’ has to be ‘iframe.html’.
Click on ‘Preview’ tab. Click on ‘+’ button and select ‘Generate PDF’. The PDF will have been generated.
Click on ‘Download’ and check the document. It will display ‘Document name:’ and the opportunity name. In this example, the name is ‘Test Opportunity’.
Go to opportunity record. The PDF is stored in the ‘Notes & Attachments’ related list.
I follow you but not function.
i not see nothing when click Preview, the problem is template ?
LikeLike
Hi Michele,
Download the file from Github (the link is on the top of the page) and upload it in your org.
Let me know if is solved your problem.
Thanks
LikeLike
Excellent post Ignacio.
One question, how can I import to my org the gitHub example you included to download?
Thanks!
LikeLike
Hi Sebastian,
Thanks for your feedback. You have to open any Vlocity tab, for example ‘Vlocity Dataraptor Designer’ and should be a button to import it.
Let me know if that worked
Thanks
LikeLike
Very interesting
LikeLiked by 1 person
Thanks Mirko
LikeLike
Is it directly attaching pdf to notes and attachments? Or is there some functionality.
LikeLike
yes, it is attached in the record’s notes and attachments
LikeLike
Hello Ignacio,
Good job! , I followed the steps, but when I click Preview I get this error: {{objDocCreationService.objDocLabel}}. Do you know what could be wrong?
LikeLike
Hi Valery,
Thanks a lot!. Can you verify that the format is the right one, please? The variables are in the template like %%OpportunityName%% and in the omniscript like %OpportunityName%
LikeLike
Hi Ignacio,
Thanks for the solution. I’ve downloaded the script from github and imported. and also adjusted id’s and values according to my org. But in prieviewits showing “Url does not exist” error.
“URL No Longer Exists
You have attempted to reach a URL that no longer exists on salesforce.com.”
Any fix?
LikeLike
Hi Ventaka,
Try to follow the steps and update the values that you think it is not pointing correctly.
Regards,
Ignacio
LikeLike
Hi Venkata,
Were you able to identify and solve the issue?
LikeLike
i follow the steps but when i click on preview its show one image. Can you please hel me here.
Thanks in Advance!!
LikeLike
Hi Hermant,
Thanks for your question. The image should be the result that you should expect. If it is a blank image, please verify that you have set the parameters correctly to show what you expect. You have to respect the Vlocity format or the values will be not render
Regards,
Ignacio
LikeLike
Hi Ignacio,
I managed to get it working fine in Omniscript designer. I currently getting an issue with the OmniScript when it placed within a Visualforce page I get shown this error – {{objdoccreationservice.objdoclabel}} do I need some values within the visualforce so {{objdoccreationservice.objdoclabel}} has something?
Best regards,
Jon
LikeLike
Hi Jon,
Thanks for your comment. Sorry I don’t have experience adding the omniscript inside a visualforce. I don’t know if it is possible or not. Try to render in other area without using a visualforce,
Good luck!
Regards,
Ignacio
LikeLike
Hi Ananya,
Thanks for your comment, Like any tool, this have some limitations but I am not sure which kind of limitation you could face in your requirements. I would recommend you to ask Vlocity support to see if you cannot meet some pf your requirements.
Good luck!
Regards,
Ignacio
LikeLike
Thanks Ill give it try, on a separate note regarding the generate PDF. Have you come across this “Input object is not a key-value pair”. I am trying to find out what it means but can’t seem to find anything on this error.
LikeLike
Hi Jon,
Thanks for Jon. Please, verify that the format is the right one.
Regards,
Ignacio
LikeLike
Dear Ignacio,
I have followed the exact steps as mentioned by you in the given post. However, i am not able to see the download option in preview. I checked the debug and data section in Omniscript preview, the document is getting generated (new doc id is created every time).
Looks like some iframe issue. I am using cmt org. Could you please help me resolve this issue?
Regards,
Priyanka
LikeLike
Dear Ignacio,
I have followed all the steps mentioned in your post but can’t see the download window. I am using communication and media org. I suspect that there might be some issue with CUSTOM HTML TEMPLATE settings.
In LWC preview, debug – i can see document id getting generated. But successfully generated pdf document and download is not coming.
Could you please help me with this at your earliest?
Best Regards,
Priyanka
LikeLike
Hi Priyanka,
Thanks for your comment. This post is a little old and the pdf generation used to cause plenty of issues in the past. I would recommend you to open a case with Vlocity because they should know how to solve the problem
Good luck!
LikeLike
Dear Ignacio, we are recruiting talented SFDC developers with Vlocity experience. Your article caught our attention. Could we arrange a zoom to see if there is a fit? -Eric
LikeLike
Hi Eric,
Thanks for your comment. Can you send me in linkdin and discuss it there, please?
https://www.linkedin.com/in/ignacio-sarmiento-losada-78049b90/
Regards,
Ignacio
LikeLike