Menu
Welcome, Guest
Username: Password: Remember me

TOPIC: How to use get_linked_beans and relationship

How to use get_linked_beans and relationship 4 months 1 week ago #80318

  • s.brown
  • s.brown's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
I have written the logic hook to send email notification but keeps giving this error message from the php file "Could not find Users within the department NC is issued to", I don't understand why it to saying that $dept_array is equivalent to zero(0). This is the name of the relationship (dept_department_nccas_nc_case)'; not sure if my syntax is incorrect or what the case maybe.

$dept_array= $bean->get_linked_beans('dept_department_nccas_nc_case','dept_Department_sugar');

if(count($dept_array)==0){
/*log error*/
$GLOBALS->fatal("Could not find the department NC was issued to: ". $bean->name);
}else{
/* Get email of users within the Department NC is issued to */
$user_array = $dept_array[0]->get_linked_beans('dept_department_users','User');
if(count($user_array)==0){
/*log error*/
$GLOBALS->fatal("Could not find Users within the department NC is issued to: ". $bean->name);
}else{
$address=getDepartmentUsersEmail($user_array);
}


/*Get the Department NC was raised by */
$raised_dept_array= $bean->get_linked_beans('dept_department_nccas_nc_case_1','dept_Department_sugar');
if(count($raised_dept_array)==0){
/*log error*/
$GLOBALS->fatal("Could not find the department NC was raised by: ". $bean->name);
}else {
/*Get email of users within the Department NC is raised by*/
$raised_user_array = $raised_dept_array[0]->get_linked_beans('dept_department_users','User');
if(count($raised_user_array)==0){
/*log error*/
$GLOBALS->fatal("Could not find Users within the department NC is raised by: ". $bean->name);
}
else {
$r_user_address = getDepartmentUsersEmail($raised_user_array);
}
}
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 6 days ago #80327

  • amariussi
  • amariussi's Avatar
  • Offline
  • SuiteCRM Is My Life
  • Posts: 1313
  • Thank you received: 291
  • Karma: 68
Does the second cll produce any result?

I see that you are using two different relationships:
. dept_department_nccas_nc_case
. dept_department_nccas_nc_case_1

Are they supposed to be different?
Are those both the correct names of the relationships

Is the name of the module (dept_Department_sugar) correct?

Is the name of the bean object ($bean) correct?

Can you try to output to screen the $bean object (then exit; otherwise the flow will continue) to see its contents. I see that $bean->name appears to be empty in the message output.
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 6 days ago #80334

  • s.brown
  • s.brown's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
dept_Department_sugar is the name of a php file with the fields and $bean->name is not empty; it printed out the subject of the nc case. Yes they are no different relationships
Last Edit: 4 months 6 days ago by s.brown.
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 6 days ago #80335

  • amariussi
  • amariussi's Avatar
  • Offline
  • SuiteCRM Is My Life
  • Posts: 1313
  • Thank you received: 291
  • Karma: 68
Have you had a look here:
docs.suitecrm.com/developer/working-with-beans/

Particularly at this portion:
get_linked_beans
The get_linked_beans method allows retrieving a list of related beans for a given record.

Example 3.14: get_linked_beans method signature
get_linked_beans(
$field_name,
$bean_name,
$sort_array = array(),
$begin_index = 0,
$end_index = -1,
$deleted=0,
$optional_where="");
$field_name
The link field name for this link. Note that this is not the same as the name of the relationship. If you are unsure of what this should be you can take a look into the cached vardefs of a module in cache/modules/<TheModule>/<TheModule>Vardefs.php for the link definition.

$bean_name
The name of the bean that we wish to retrieve.

$sort_array
This is a legacy parameter and is unused.

$begin_index
Skips the initial $begin_index results. Can be used to paginate.

$end_index
Return up to the $end_index result. Can be used to paginate.

$deleted
Controls whether deleted or non deleted records are shown. If true only deleted records will be returned. If false only non deleted records will be returned.

$optional_where
Allows filtering the results using an SQL WHERE clause. See the get_list method for more details.

Results
get_linked_beans returns an array of the linked beans.

Example 3.15: Example get_linked_beans call
$accountBean->get_linked_beans(
'contacts',
'Contacts',
array(),
0,
10,
0,
"contacts.primary_address_country = 'USA'");
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 5 days ago #80336

  • s.brown
  • s.brown's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
I'm not understanding because the same relationship that I used that's the link definition in cached vardefs that I used; but some how the count is still zero. Yes I did look at that forum
Last Edit: 4 months 5 days ago by s.brown.
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 5 days ago #80337

  • amariussi
  • amariussi's Avatar
  • Offline
  • SuiteCRM Is My Life
  • Posts: 1313
  • Thank you received: 291
  • Karma: 68
But in your code you seem to be using two different relationships:
. dept_department_nccas_nc_case
. dept_department_nccas_nc_case_1
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 5 days ago #80338

  • s.brown
  • s.brown's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
I have removed one but it still produces the error "Could not find the department NC was issued to: ". $bean->name
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 5 days ago #80339

  • amariussi
  • amariussi's Avatar
  • Offline
  • SuiteCRM Is My Life
  • Posts: 1313
  • Thank you received: 291
  • Karma: 68
If you create a relationship, and then delete it and then recreate it you may end up in trouble not finding the correct relationship that you have to use.

Please try your code first with dept_department_nccas_nc_case and check if it works. Then modify the cde and try with dept_department_nccas_nc_case_1 (the difference being the "_1" at the end)

Please check also your logs and report any errors
Last Edit: 4 months 5 days ago by amariussi.
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 5 days ago #80340

  • s.brown
  • s.brown's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
That didn't work either. And the only error is this
Mon Apr 15 07:08:57 2019 [6960][e19f62c5-9f87-02bc-204f-5a57c41e1cd1][FATAL] Could not find the department NC was issued to: hjggggf
Mon Apr 15 07:08:57 2019 [6960][e19f62c5-9f87-02bc-204f-5a57c41e1cd1][FATAL] Could not find the department NC was issued to: hjggggf
" hjggggf" is the subject of the nc case that I entered and that's the result showed suitecrm.log
Last Edit: 4 months 5 days ago by s.brown.
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 5 days ago #80346

  • amariussi
  • amariussi's Avatar
  • Offline
  • SuiteCRM Is My Life
  • Posts: 1313
  • Thank you received: 291
  • Karma: 68
Check also the webserver/PHP log
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 4 days ago #82059

  • AlxGr
  • AlxGr's Avatar
  • Offline
  • Elite Member
  • Posts: 311
  • Thank you received: 54
  • Karma: 9
I'll recommend to find the right relationship name. You can find a file containing it if you go to:

custom/Extension/modules/YourMODULE/Ext/Vardefs

You can find the name from From Studio as well


Now when you have it you can print the result into a file to check what the array is returning.
$file = 'custom/MyfileNAme.txt';
file_put_contents($file, 'This the returned content on the array: '.var_export(TheArrayYouWant, true).';\n?\>');

This is not the solution to your problem but at least will give you more inside on what is wrong.

Thanks,

AlxGr
I can help you with your customization. Requests at ctmprograATondsystemsDOTcom
No dude en contactarme si necesita personalizar su aplicación. Mi email es ctmprograARROBAondsystemsPUNTOcom
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 4 days ago #82071

  • s.brown
  • s.brown's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Saying that the array is empty
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 3 days ago #82098

  • s.brown
  • s.brown's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Thanks everyone for your assistance but the relationship name was the tricky that caused the error; eberything is working ok now. Only issue is that email notifications are coming twice
The administrator has disabled public write access.

How to use get_linked_beans and relationship 4 months 3 days ago #82099

  • amariussi
  • amariussi's Avatar
  • Offline
  • SuiteCRM Is My Life
  • Posts: 1313
  • Thank you received: 291
  • Karma: 68
I am glad to hear that you have managed to sort it out.

In my first post and also after I concentrated on the name of the relationship:
Are those both the correct names of the relationships

...
The administrator has disabled public write access.
Time to create page: 0.055 seconds
Powered by Kunena Forum