PDF Template - Custom formatting string in templateparser

Back !
I have a little question more for the fields parsing in this file.

When i use some custom fields, i have a field in the template with a name like : “aos_xxxxxxxx…c”.
I can parse them easily with and choose how to show them.

Now, if i use the field already included in the crm, like for example “$billing_account_name”, even if i had a formating in my code with :

if ($name === 'billing_account_name'){
//my formating code here
}

The code is never read…
My question is : for the core fields, how i can parse them to have the same behavior than my custom fields ?

I have checked the parser but i dont see where it is done (there should be a code somewhere but i cant find it…).

Thanks for any help :slight_smile:
Xavier

It’s probably account_billing_account_name or accounts_billing_account_name

The $repl_array is prepared in the cycle before that one where you are. You can use print_r($repl_array) or var_dump($repl_array) as debugging tools to see everything that’s permissible.

Hi Pgr :slight_smile:
Happy to see you are still here !!

I have tried the print_r and var_dump. Unfortunately, i’m not enough good to get this working (nothing on screen or in console or in the generated pdf… I have also tried to assign the result to the var $string to see if I can get the result in the pdf, but all is “blank”).

What is strange in what you say about account_billing_account_name is the name have been retrieved from the dropdown in the pdf template constructor in SuiteCrm.
If i use the field, it works : i can get the value in the result.
But if i add my formating condition, the condition is never read : how the field could works if not formated but not read ? I dont get this…

To be completely clear :
I have in the editor for the PDF template the field called :
" Société / Compte : $billing_account_name"
The field show me correctly the field value (so, this is correctly called in the pdf)
With my condition (given before in my previous post), the condition is never read (i have put another condition to fill in both cases empty or not empty and i get nothing at all).
How this field could be “read” with this field name if this not corresponding to the name in the condition ?? This is what i dont get…

If you could give me the example code to put in my parser to see all the tab (again : nothing on screen, nothing on pdf, nothing on console… and i have changed your example from $repl_array to the name in the file as $repl_arr…

Thanks again for all the time you spend here to help me :slight_smile:
Xavier

You need to look at the code and see what it’s doing.

The parse_template function does this:

  • it receives an array of beans (normally containing only one, I expect)
  • for each of those beans, it will run parse_template_bean for the bean itself, and then iterate each relate field, get the corresponding bean, and also run parse_template_bean on that

So parse_template_bean will actually be run often, each time replacing variables from different modules.

The parse_template_bean function does this:

  • runs a 1st cycle for each field in the module, building a $repl_array which is an array listing each potential variable name and its replacement value. The generic format will be module name (or relate field name), followed by an underscore, followed by the field name:

    $repl_arr[$key . "_" . $fieldName] = $focus->$fieldName;
    
  • runs a 2nd cycle actually doing the replacements


For the accounts module, the parse_template_bean will successively be called with a $key of:

  • accounts
  • modified_by_name
  • created_by_name
  • assigned_user_id
  • assigned_user_name
  • parent_name
  • campaign_name

Bottom line, I think you just have a confusion with field names… it’s not $billing_account_name, it’s a bunch of $billing_address_... fields, seen here in my debugger:

image

Thanks again PGR :slight_smile:
I will try all this (really, thanks for your explanation !) and will come back with other questions if needed.
Just one question : what do you use to get these vars shown ? You work locally ?
This is what i miss : i dont know how to show the vars and somewhere, i work as a “blind”…

Thanks PGR, i repeat it again, but you help me a lot :slight_smile:

Xavier

I should not making the right move…

To try to find the “correct” string, i add what you suggest before the var name : “account_…” (no success) and “accounts_…” (no success). I also try with contact_… just in case (no success).

So, to try to find the correct var names, i have tried this : at the bottom of the file, i have replaced the line like this :

 //$string = str_replace("\$$name", $value, $string);
                $string = str_replace("\$$name", $name, $string);

I can see then the “name” of the vars instead of the content.
The thing is : i still see the var with the name “billing_account_name”.

If i dont “put you on the nerve” with my stupid questions, i will be very gratefull if you can help me some more on these 2 last questions…
I understand what you wrote before with the key, but dont get how to get the correct name to make my test and format as i want the core vars… If i understand you well, it should be “accounts_billing_account_name” but i should miss something again in your explanation.

Can you try on your side if this is not to much asked and if you have time for this to see what i’m doing wrong ? I’m obviously doing the wrong thing but i dont see what…

Thanks again Pgr :slight_smile:
Xavier

SuiteCRM doesn’t have a field called billing_account_name. Where do you see that field?

EDIT: if you created it (custom field) then try accounts_billing_account_name_c

Hi again Pgr,
I assure you, i use the account name !
I have made a screenshot…

Xavier
account_name_SCRM-Screenshot_20200908_212435

To exclude language issue with translation, i check in english also : the field is here too :
contactname-uk-Screenshot_20200908_225036

That just looks like a bug in the dropdowns. Do you see that field anywhere else in SuiteCRM? In a view? In Studio? What are those fields supposed to mean?

uh… i find a field name in account but not in contact… Is this a “calculated fields” (using the first and last name) existing in the dropdown ?
If there is no direct field, how this could show me the name of the person ???
So strange…

Thanks Pgr :slight_smile:
Xavier

Do you have a relate field called “billing”?

Hi Pgr,
No, no : this is the “core fields” used here…
I make some screenshot and i come back…
Xavier

Here it is :

This is filled during the quotation.
Xavier

Where is that? I don’t see it.

Check the online demo to see if it looks the same as your system:

https://www.softaculous.com/demos/SuiteCRM

And check your Studio and pay attention to any additional customizations: relationships, relate fields, new fields

Hi Pgr,
It is exactly the same thing on the demo : Quotes -> Create (on the demo), you have the exact same thing.

Thanks for your time :slight_smile:
Xavier

Ah, so you’re on Quotes module, not Accounts.

That field seems to be called

$aos_quotes_billing_account

Composed like this:

$key is aos_quotes

$focus->$fieldName is billing_account

Hi pgr,
Ok, i can now have my full parser wirking correctly.

One last question :
If i want to have a “table” build with several fields, i cannot no ?
Imagine something like :
table - tr - td firstfield /td td secondfield /td /tr /table
As one field is read on each loop, i cannot have several fields in the table with something like if field1 is filled, show field1 and field 2
I have tried to assign the value in a custom var in the code, but the value seems to be lost on each loop (tried static, global, etc…, no success : i have to parse fields one by one).

If you know a solution for this… :slight_smile:
Thanks for all your help done pgr !
By the way, if you know a solution for my other question here, please tell me !
Need some explanation on how works import inbound emails
and
Understanding also the email management
Thanks pgr :wink:
Xavier

Hi @Chabi02

Maybe you’ve solved this by now , but if you haven’t, or for others that have the same question :

Yes you can reference many other fields, provided you do not add them to the template. Only add one of the fields to the template (eg $firstfield). Then in templateParser.php only check for this field, and reference any other fields, eg

if ($name === 'firstfield') {
$value = "<p>".$value." - ".$repl_arr['secondfield']."</p>";}

Hi EugeneP,
This change a lot of thing indeed : if i had this information sooner, i would have create my templateparser differently :slight_smile:

Thanks for this information : i will try (not right now) this solution for other PDF.
Then, I could ask an other question : is this possible to indicate to the PDF a different parser file ?

Thanks to everybody, and especially to all who have helped me :slight_smile:
Xavier