Reply
doyeli Support Team

Support Team

Support Team
Posts: 284
Registered: ‎01-08-2016
Accepted Solution

How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Problem Statement: 

 

I have written a plugin that populates some default values in the Zuora
Quote. We have not been able to get any value to be displayed
quote.zqu__InvoiceOwnerId__c in the UI.



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

doyeli Support Team

Support Team

Support Team
Posts: 284
Registered: ‎01-08-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Solution:

 

The code that initializes the values for this lookup is called before the the code that runs the custom plugin.So it is rendered without the correct values set.

The part that initializes the InvoiceOwner Lookup values happens during the custom plugin line,

super.populateDefaultFieldValue(record, pcc);

 

When this method is called, it sets the basic information on the quote (Default Quote Name, Account, Opportunity, Zuora ID...), and also initializes the lookup.

In this case, it happens before the values are set.

So by calling the the parent populateDefaultFieldValue again after the invoice owner fields are set, it should properly initialize the InvoiceOwner fields.

 

Here is the Plugin code that will work

 

 

global class MyCreateQuoteDefaultValues extends zqu.CreateQuoteController.PopulateDefaultFieldValuePlugin{
global override void populateDefaultFieldValue(SObject record, zqu.PropertyComponentController.ParentController pcc) {
super.populateDefaultFieldValue(record, pcc);
Id accountId = (Id) record.get('zqu__Account__c');
List<zuora__CustomerAccount__c> billingAccounts = [SELECT Id, Name, zuora__Account__c FROM zuora__CustomerAccount__c WHERE zuora__Account__c = :accountId];
if (billingaccounts .size() > 0) {
record.put('zqu__InvoiceOwnerId__c', billingaccounts[0].Id);
record.put('zqu__InvoiceOwnerName__c', billingaccounts[0].Name);
} 
// (The following call initializes the lookup.)
super.populateDefaultFieldValue(record, pcc);
record.put('zqu__InitialTerm__c', 11);
}
}

 

Please Note: In this example, populateDefaultFieldValue is called twice, because the plugin contains logic that reads from the zquAccountc field, which also gets populated by this method.

it's a workaround for this specific issue.

In the long term, we'd want to call the method that sets the InvoiceOwner fields after the plugin executes in the package so that there is no need to  call this method twice. We have an internal Jira Ticket to  track this.

 



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

vasudeva_shenoy Partner

Partner

Partner
Posts: 29
Registered: ‎07-18-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Hi Doyeli, 

 

This post is really helpful. I am trying this out to default a value on Invoice owner from opportunity object. I am able to default the value and show to the end user. However its not getting saved under Quote.zqu__InvoiceOwnerName__c or zqu__InvoiceOwnerId__c.

 

Here is the code snippet. Can you please help what is wrong here?

 

global class DefaultValuesPlugin extends zqu.CreateQuoteController.PopulateDefaultFieldValuePlugin
{
global override void populateDefaultFieldValue
(SObject record, zqu.PropertyComponentController.ParentController pcc)
{

super.populateDefaultFieldValue(record, pcc);
//Populate default values in the quote header

// Retrieve the account ID from the quote
Id oppId = (Id) record.get('zqu__Opportunity__c');
System.debug('Opportunity id: '+ oppId);
// Find the contacts associated with the account
List<Opportunity> OppList = [SELECT Id,AccountId,Name,Invoice_Owner__c,End_User__c from Opportunity where Id =: oppId];
System.debug('OppList values: '+ OppList);
Set<Id> InvId = new Set<Id>();
if (OppList.size() > 0)
{
InvId.add(OppList[0].Invoice_Owner__c);
record.put('zqu__InvoiceOwnerId__c',OppList[0].Invoice_Owner__c);
//record.put('zqu__InvoiceOwnerName__c',OppList[0].Invoice_Owner__c);
record.put('End_User__c',OppList[0].End_User__c);
}
List<Zuora__CustomerAccount__c> BillingAcntList = [SELECT Id,Name from Zuora__CustomerAccount__c where Id =: InvId];
if(BillingAcntList.size()>0)
{
record.put('zqu__InvoiceOwnerName__c',BillingAcntList[0].Name);
}
System.debug('BillingAcntList: '+ BillingAcntList)

super.populateDefaultFieldValue(record, pcc);

}
}

doyeli Support Team

Support Team

Support Team
Posts: 284
Registered: ‎01-08-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

HI @vasudeva_shenoy I will test on my end and get back to you

 

Thank you

doyeli



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

vasudeva_shenoy Partner

Partner

Partner
Posts: 29
Registered: ‎07-18-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Hi Doyeli,

 

Any update on this? Also I noticed, this field does not seem to be a lookup. It appears like lookup in UI but has 2 text based fields on the backend. Even we tried to update these 2 fields through process builder but it does not seem to be working.

 

Thanks

Vasu

doyeli Support Team

Support Team

Support Team
Posts: 284
Registered: ‎01-08-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Hi @vasudeva_shenoy,

 

I am able to reproduce as well in later version of ZQuote.

I am checking with Engineering and send you an  update

 

Thank you

Doyeli



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Highlighted
doyeli Support Team

Support Team

Support Team
Posts: 284
Registered: ‎01-08-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

[ Edited ]

Hi @vasudeva_shenoy I have used the following code in zQuote release 8.8.1 and could make it work

 

Global class InvoiceOwnerDefaultValues extends zqu.CreateQuoteController.PopulateDefaultFieldValuePlugin {
  // Override the function "populateDefaultFieldValue" of the parent class so that we can set default values.
  public override void populateDefaultFieldValue (SObject record, zqu.PropertyComponentController.ParentController pcc) {

    super.populateDefaultFieldValue(record, pcc);
    // Set the Invoice Owner Information (From the soldToAccount) Details.
    List<Zuora__CustomerAccount__c> billingAccounts
        = [SELECT Id, Name, Zuora__Account__c,Zuora__Zuora_Id__c
                   FROM Zuora__CustomerAccount__c WHERE Zuora__Account__c = '00141000007Pw0Z'];
    if (billingAccounts.size() > 0) {
     //List soldToAccount = billingAccounts[0];
      record.put('zqu__InvoiceOwnerName__c', billingAccounts[0].Name);
      record.put('zqu__InvoiceOwnerId__c', billingAccounts[0].Zuora__Zuora_Id__c);

      // Client must call this method explicitly from the plugin to initialize Invoice Owner lookup.
      super.populateInvoiceOwner(pcc);
    }

  }
}

 

Please test on your end and let me know .

 

Thank you
Doyeli



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Kenta New Student ZEO

New Student ZEO

New Student ZEO
Posts: 1
Registered: ‎08-17-2017

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Hi @doyeli

 

Thank you for the article. The plugin runs successfully on New Subscription Quote but not on Amendment Quote. Am I missing something or can it not update the Invoice Owner on Amendment Quote by design? 

vasudeva_shenoy Partner

Partner

Partner
Posts: 29
Registered: ‎07-18-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Thanks, Doyeli for the help. It worked.

doyeli Support Team

Support Team

Support Team
Posts: 284
Registered: ‎01-08-2016

Re: How to populate Invoice Owner field using PopulateDefaultFieldValuePlugin

Thank you @vasudeva_shenoy for the confirmation.



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √