So I've been looking for a way to basically add some text to the headerpane.hbs file for the Accounts module.
I copied
Fullscreen
1
clients/base/views/record/headerpane.hbs
to
Fullscreen
1
custom/modules/Accounts/clients/base/views/record/headerpane.hbs
The code I've added looks like:
Fullscreen
1
2
3
4
5
6
7
<span style="display:table-cell;vertical-align:top;position:relative;padding:18px 18px 0px 20px;width:100%;">
{{#if days_past_due_c}}
<span style="border:1px solid #282828;border-radius:3px;padding:4px;background-color:#E61717;color: white;">PAST DUE</span>
{{else}}
<span style="border:1px solid #282828;border-radius:3px;padding:4px;background-color:#32800E;color: white;">CURRENTS</span>
{{/if}}
</span>
I know the if statement won't work like that, but its just an example. If $bean->days_past_due_c has a value, then I want to show a bright big red banner in the header pane that says "PAST DUE", otherwise it can just say "CURRENT".
But for the life of me, I can't find any good documentation that shows how to reference a fields value from here within the if statement.
I saw the fieldValue() API call but also don't see a way to use that inside an if statement.
Sugar Version: 7.8
UPDATE: I figured out by adding {{log this}} per the documentation I could get everything available to the handlebar template. I looked through and saw the field value in the data (in several places), but can't seem to access it. Not sure whats wrong with the syntax.
{{view.model.attributes}} will spit out all the fields are their values, but if say {{view.model.attributes.days_past_due_c}} it returns undefined.
UPDATE #2: So I thought maybe the JSON response I see isn't "really" JSON since much of what returns is actually functions and methods. So maybe thats why I can see it but not access it directly.
So I extended the record.js file (copied from modules/Accounts/client/base/views/record/record.js) to same folder path in custom/
Here is what my syntax looks like presently (based on example given here: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_11.0/Cookbook/Passing_Data_to_Templates/)
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
({
extendsFrom: 'RecordView',
/**
* @inheritdoc
*/
initialize: function(options) {
//populate your data
accountData=new Object();
this.accountData = accountData;
let self = this;
this.plugins = _.union(this.plugins || [], ['HistoricalSummary']);
app.api.call("read", app.api.buildURL("Accounts/"+options.context.attributes.modelId), null, {
success: function (accountResponse) {
self.accountData['fields'] = accountResponse;
}
});
this._super('initialize', [options]);
},
I then logged this in headerpane.hbs and I see 'this' outputted, 'view.accountData' shows up, next two show up as undefined, last one doesn't show up at all.
Fullscreen
1
2
3
4
5
6
7
{{log this}}
{{log view.accountData}}
{{log view.accountData.fields}}
{{log view.accountData.fields.days_past_due_c}}
{{#with accountData}}
{{log fields.days_past_due_c}}
{{/with}}