Why doesn't BeanFactory("module name", id) return the record from the db?

Hello World, 

So I have an api call that is working.  That is I can put in the url and some argument and print out that argument. I want to get some data using beans,  I know that I am clearly doing something wrong because nothing is return what I expect it to.  For example I have this code:

$accountID = '1d53d7c0-5783-9a99-09a6-555e943c52cb';

$accountBean = BeanFactory::getBean("Accounts",$accountID);

//Shouldn't this return the record the db?

return $accountBean;

According to the documentation on the developer site when you add the ID of the bean you want the bean factory should return the record from the db. Correct?

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.5/API/Classes/BeanFactory/#Retrieving…

 

This is the value from the db:

So shouldn't I expect to see a bean representing that record with that data that have a name property of Internal testing Team?

When I test the code using postman I get this instead:

As you can see I can search for the name value but nothing is there. It appears to just be the definition of the object that I returned and not the record from the database.

Why is this?  Can someone please shed light on my problem.

Best Regards

  James Palmisano

  • Hi James,

    What if you use retrieveBean() instead of getBean()?

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Data_Framework/Models/BeanFactory/#…

    There "null will be returned instead of an empty bean object if the retrieve fails".

    If it returns null the question would be why the retrieve fails. Can you shed some light how you implemented that customization? Is it a logic hook for example?

    Thanks,

    Dennis

  • So that code is run in a class that extends the api.  The api call is working as I said before.  You can go to the url if you are logged in and then it will return some dummy array in json form.

  • I just tried the code to retrieved the bean instead of getBean and null is returned

    So this bean isn't found but the record is there.  hmmmmm maybe rebuild indices?

  • elastic search has a bunch of errors

    [2016-07-11 12:20:26,180][WARN ][cluster.service          ] [Daniel Rand] failed to reconnect to node [Daniel Rand][ndr9PaohRIuLCfIJfcGjsQ][FLSARMAC1375.local][inet[/10.0.0.4:9300]]

    org.elasticsearch.transport.ConnectTransportException: [Daniel Rand][inet[/10.0.0.4:9300]] connect_timeout[30s]

      at org.elasticsearch.transport.netty.NettyTransport.connectToChannels(NettyTransport.java:807)

      at org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:741)

      at org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:714)

      at org.elasticsearch.transport.TransportService.connectToNode(TransportService.java:150)

      at org.elasticsearch.cluster.service.InternalClusterService$ReconnectToNodes.run(InternalClusterService.java:544)

      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

      at java.lang.Thread.run(Thread.java:745)

    Caused by: org.elasticsearch.common.netty.channel.ConnectTimeoutException: connection timed out: /10.0.0.4:9300

      at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:139)

      at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:83)

      at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)

      at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)

      at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)

      at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)

      ... 3 more

  • Dumb question: are you sure you are looking at the same instance of Sugar from the script and from the MySQL workbench?

    I juggle three development instances and it has happened that I think I'm on one when I'm on another...

    FrancescaS

  • Yes I am sure. I only have one.

  • Which user context are you using when attempting to access that record? Are you logged into the API as a user that would be able to see that account record via the main web app?

  • I am using my own user credentials to create an OAuth token

    Then I use that token to call the url in postman

    Angel Magana

  • The client_id is defined as such

    It appears that I am a sugar user when I use this client_id

    Is this the problem?

1 2