Sugar Dev Tricks: Retrieving JavaScript Bean Models

Share

Facebook
Twitter
LinkedIn

Thanks for reading my first development entry.  If you’re new to developing on Sugar 7.x and 8.x, you might be a bit overwhelmed by the differences from previous versions of Sugar.  With these new versions we can take advantage of CRUD development directly on the client-side (browser) without having to write specific code in PHP.  With the new versions of Sugar, a new library called backbone.js was added.  You can take advantage of this robust library by using “beans” which are JavaScript objects that extends all the functionalities of a Backbone Model from SugarCRM.

Let’s say we want to retrieve a Lead record, with an ID of “ea68c454-851a-11e8-81e7-000d3af74b0f”, you can try the following codes:

var leadId = 'ea68c454-851a-11e8-81e7-000d3af74b0f'
var lead = App.data.createBean('Leads');
lead.set('id', leadId);
lead.fetch({success: function(model, data){
console.log(model, data, lead); 
// this will  log 3 items in the dev console, model will be the updated model
// model will log the updated model, with the data updated from the ajax response
// data is the response object from the ajax call
// lead will be the backbone model we executed the fetch method (same value as model)
}});
When should I use this?
  1. Let’s say we have a custom field that bases the value from a relate field (eg. relate_field + related_field_id), and you will need additional values from the relate_field’s record (eg. description, date_entered). You can fetch the record using app.data.createBean() from your custom field, specify on how you will display the retrieved values , and then call the render method.
  2. You can use this on Dashlets where you want to display the record on a specific sort of way. You can call the app.data.createBean() on the loadData() method of the dashlet, specify on how you will display the retrieved values, then call the render().

That’s it for my quick tip.  Thanks for reading!

Upcoming Events

SEPTEMBER 2022

SEPTEMBER 6th MONDAY.COM COURSE
SEPTEMBER 8th MONDAY.COM COURSE

OCTOBER 2022

OCTOBER 11th MONDAY.COM COURSE
OCTOBER 13th MONDAY.COM COURSE

NOVEMBER 2022

NOVEMBER 15th MONDAY.COM COURSE
NOVEMBER 17th MONDAY.COM COURSE

Our Industry Learning
software partners

Our Experts Can Help

First Name
Last Name
Email
What can we help with?
Anything else we should know?

Recent Posts

Categories

Newsletter

Newsletter Sign-up *

Get insider tips, industry news and content specific for CRM, Salesforce, SugarCRM and monday.com – all for free!

August 2022

MO
TU
WE
TH
FR
SA
SU
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
Events for August

1st

No Events
Events for August

2nd

No Events
Events for August

3rd

No Events
Events for August

4th

No Events
Events for August

5th

No Events
Events for August

6th

No Events
Events for August

7th

No Events
Events for August

8th

No Events
Events for August

9th

No Events
Events for August

10th

No Events
Events for August

11th

No Events
Events for August

12th

No Events
Events for August

13th

No Events
Events for August

14th

No Events
Events for August

15th

No Events
Events for August

16th

No Events
Events for August

17th

No Events
Events for August

18th

No Events
Events for August

19th

No Events
Events for August

20th

No Events
Events for August

21st

No Events
Events for August

22nd

No Events
Events for August

23rd

No Events
Events for August

24th

No Events
Events for August

25th

No Events
Events for August

26th

No Events
Events for August

27th

No Events
Events for August

28th

No Events
Events for August

29th

No Events
Events for August

30th

Events for August

31st

No Events
Events for September

1st