I have a Vlocity Document Template which needs to fill through a custom class. (Token Mapping Method).
When a run the doc generation by OmniScript (client-side), the document tokens are filled with blanks. I don´t know what´s wrong. Anybody can help me? The Custom Class is below.
global without sharing class PME_QuotePDF implements vlocity_cmt.VlocityOpenInterface2{
global Object invokeMethod(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> options)
{
Boolean success = false;
try{
if (methodName == 'getTokenData'){
getTokenData(input, output, options);
success = true;
}
} catch (Exception e){
System.debug(LoggingLevel.DEBUG, 'Exception type caught: ' + e.getTypeName());
System.debug(LoggingLevel.DEBUG, 'Message: ' + e.getMessage());
System.debug(LoggingLevel.DEBUG, 'Cause: ' + e.getCause());
System.debug(LoggingLevel.DEBUG, 'Line number: ' + e.getLineNumber());
System.debug(LoggingLevel.DEBUG, 'Stack trace: ' + e.getStackTraceString());
}
System.debug('invokeMethod:output -> ' + output);
System.debug('invokeMethod:success -> ' + success);
return success;
}
global static Boolean getTokenData(Map<String, Object> input, Map<String, Object> output, Map<String, Object> options)
{
System.debug('########## START PME_QuotePDF.getTokenData');
try {
System.debug('INPUT: '+input);
System.debug('OPTIONS: '+options);
Id quote_Id = (String)input.get('contextId');
System.debug('quote_Id: '+quote_Id);
Map<String, QuoteLineItem> mapString = new map<String, QuoteLineItem>();
TransformGetQuoteDetails pW = new TransformGetQuoteDetails();
pW.products = new List<CustomProduct>();
Map<String, List<CustomProduct>> mapPDFWrapper = new Map<String, List<CustomProduct>>();
Quote quote = [SELECT Opportunity.Account.FormattedDocument__c, Opportunity.Account.NameFull__c, QuoteNumber, CreatedBy.Resale__c, ProposalProductsAmount__c, Validity__c, CommercialConditions__c, CreatedBy.Email, CreatedBy.Name, CreatedBy.MobilePhone
FROM Quote
WHERE Id =:quote_Id
];
List<QuoteLineItem> listQuoteLn = [Select id, Quantity, Product2.Name,vlocity_cmt__AssetReferenceId__c, ReliesOnReferenceId__c, UnitPrice, TotalPrice, product2.vlocity_cmt__Type__c FROM QuoteLineItem WHERE QuoteId =:quote_Id];
for(QuoteLineItem quoteLn : listQuoteLn){
mapString.put(quoteLn.vlocity_cmt__AssetReferenceId__c, quoteLn);
}
for(QuoteLineItem quoteLn : mapString.values()){
// DADOS APENAS DE TESTE
pW.BusinessDocumentNumber = quote.Opportunity.Account.FormattedDocument__c;
pW.CustomerFullName = quote.Opportunity.Account.NameFull__c;
pW.CustomerQuoteNumber = quote.QuoteNumber;
pW.DealerFullName = quote.CreatedBy.Resale__c;
pW.GrandTotalPriceValue = String.valueOf(quote.ProposalProductsAmount__c);
pW.ProposalValidity = (Integer)quote.Validity__c;
pW.RTB_CommercialCondition = quote.CommercialConditions__c;
pW.SalesEmail = quote.CreatedBy.Email;
pW.SalesFullName = quote.CreatedBy.Name;
pW.SalesMobilePhoneNumber = quote.CreatedBy.MobilePhone;
// DADOS APENAS DE TESTE
String reliesOnId = quoteLn.ReliesOnReferenceId__c;
Boolean hasParenteQuote = mapString.containsKey(reliesOnId) ? true : false; //quoteLn é filho de alguém?
QuoteLineItem parenteQuote = hasParenteQuote ? mapString.get(reliesOnId) : null;
if(hasParenteQuote){
CustomProduct cProd = new CustomProduct();
String quoteType = quoteLn.product2.vlocity_cmt__Type__c;
String parentType = parenteQuote.product2.vlocity_cmt__Type__c;
if(parentType == 'Franquia' && (quoteType == 'Bonus' || quoteType == 'Aparelho')){
switch on quoteType {
when 'Bonus' {
QuoteLineItem planQuote = mapString.get(parenteQuote.ReliesOnReferenceId__c);
cProd.ProductFullName = planQuote.Product2.Name;
cProd.Franchise = parenteQuote.Product2.Name;
cProd.QuantityLineValue = (Integer)parenteQuote.Quantity;
cProd.Bonus = quoteLn.Product2.Name;
cProd.UnitPriceLineValue = parenteQuote.UnitPrice;
cProd.TotalPriceLineValue = parenteQuote.TotalPrice;
if(mapPDFWrapper.containsKey(cProd.Franchise)){
for(List<CustomProduct> listPDFWrapper : mapPDFWrapper.values()){
for(CustomProduct pdfW : listPDFWrapper){
if(pdfW.Bonus == ''){
pdfW.Bonus = cProd.Bonus;
}else if(pdfW.Bonus == cProd.Bonus){
pdfW.QuantityLineValue = pdfW.QuantityLineValue + cProd.QuantityLineValue;
pdfW.TotalPriceLineValue = pdfW.TotalPriceLineValue + cProd.TotalPriceLineValue;
}else{
mapPDFWrapper.get(cProd.Franchise).add(cProd);
}
}
}
}else{
mapPDFWrapper.put(cProd.Franchise, new List<CustomProduct>{cProd});
}
}
when 'Aparelho' {
cProd.ProductFullName = quoteLn.Product2.Name;
cProd.Franchise = '';
cProd.Bonus = '';
cProd.QuantityLineValue = (Integer)quoteLn.Quantity;
cProd.UnitPriceLineValue = quoteLn.UnitPrice;
cProd.TotalPriceLineValue = quoteLn.TotalPrice;
pW.products.add(cProd);
}
}
}else if(parentType == 'Plano' && quoteType == 'Franquia'){
if(!mapPDFWrapper.containsKey(quoteLn.Product2.Name)){
QuoteLineItem planQuote = mapString.get(reliesOnId);
cProd.ProductFullName = planQuote.Product2.Name;
cProd.Franchise = quoteLn.Product2.Name;
cProd.QuantityLineValue = (Integer)quoteLn.Quantity;
cProd.Bonus = '';
cProd.UnitPriceLineValue = quoteLn.UnitPrice;
cProd.TotalPriceLineValue = quoteLn.TotalPrice;
mapPDFWrapper.put(cProd.Franchise, new List<CustomProduct>{cProd});
}
}
}
}
for(List<CustomProduct> listPDFWrapper : mapPDFWrapper.values()){
pW.products.addAll(listPDFWrapper);
}
output.put('tokenMap', JSON.serialize(pW));
//System.debug('#drProcessResult: '+drProcessResult);
System.debug('#OUTPUT: '+output);
System.debug('#products: '+pW.products);
System.debug('########## END PME_QuotePDF.getTokenData');
return true;
} catch (Exception e) {
System.debug(LoggingLevel.DEBUG, 'Exception type caught: ' + e.getTypeName());
System.debug(LoggingLevel.DEBUG, 'Message: ' + e.getMessage());
System.debug(LoggingLevel.DEBUG, 'Cause: ' + e.getCause());
System.debug(LoggingLevel.DEBUG, 'Line number: ' + e.getLineNumber());
System.debug(LoggingLevel.DEBUG, 'Stack trace: ' + e.getStackTraceString());
return false;
}
}
global class TransformGetQuoteDetails
{
public List<CustomProduct> products { get; set; }
public String SalesMobilePhoneNumber { get; set; }
public String CustomerQuoteNumber { get; set; }
public String BusinessDocumentNumber { get; set; }
public String DealerFullName { get; set; }
public String SalesEmail { get; set; }
public String CustomerFullName { get; set; }
public String GrandTotalPriceValue { get; set; }
public Integer ProposalValidity { get; set; }
public String SalesFullName { get; set; }
public String RTB_CommercialCondition { get; set; }
}
global class CustomProduct
{
public Double TotalPriceLineValue { get; set; }
public Integer QuantityLineValue { get; set; }
public Double UnitPriceLineValue { get; set; }
public String ProductFullName { get; set; }
public String Bonus { get; set; }
public String Franchise { get; set; }
}
class CustomTokenDataExtractorException extends Exception {
}
}