如何使用getbeans和关系字段
How to use getbeans and relationship field
我正在 suitecrm 中设置一个逻辑挂钩,以允许将 nc 案例通过电子邮件发送给提出问题的部门;我不断收到错误消息“无法在 NC 发布到的部门内找到用户;表明 dept_array 等于零。我要使用 getbeans 和关系 tables。我创建了关系dept_department_nccas_nc_case 在 suitecrm 中,但 table 中没有数据,所以我想知道是不是这个原因,还是我的语法不正确。
class nc_email_notification {
public function email_notification(&$bean, $events, $arguments){
/*define 'review_pending' as string constant */
/*Get sugar email engine*/
$email = new SugarPHPMailer();
$email->From = 'suitecrm@gmail.com';
$email->FromName ='SuiteCRM';
/*Get the Department NC was Issued to */
$dept_array= $bean->get_linked_beans('dept_department_nccas_nc_case','dept_Department_sugar');
if(count($dept_array)==0){
/*log error*/
$GLOBALS['log']->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['log']->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['log']->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['log']->fatal("Could not find Users within the department NC is raised by: ". $bean->name);
}
else {
$r_user_address = getDepartmentUsersEmail($raised_user_array);
}
}
/*Get the Quality Systems Department*/
//$qual_dept=$dept_array[0]->retrieve)by)string_fields(array('name' => 'Quality Systems' ));
//$qual_dept->load_relationship('dept_department_email_addresses_primary');
/* Send email to Manager */
$rev_email = 'ramon@gmail.com';
/*Get NC Action for the NC Case*/
$action_array = $bean->get_linked_beans('nccas_nc_case_ncact_nc_action','ncact_NC_Action_sugar');
/* Get sugar template engine */
$xtpl = new XTemplate("XTemplate/NCEmailTemplate.html");
/*GEt the URL for the NC Case */
$url = $GLOBALS['sugar_config']['site_url'].'index.php?module=ncase_NonConformance&action=DetailView&record='.$bean->id;
$xtpl -> assign('URL', $url);
/* Get NC Status */
$nc_status=trim($bean->getFieldValue('status'));
/* Get NC ID */
$id = $bean->getFieldValue('id');
if(empty($bean->fetched_row['id'])){
$email=createNCEmail($email,$rev_email,'New NC Email Notification',$bean,$xtpl);
/* Send email to Quality System Manager */
$email->addaddress($rev_email);
/* Send email to users of Issued to department */
foreach($address as $uemail){
$email->addAddress($uemail);
}
}else {
if (strcasecmp ($nc_status,'review_pending')==0){
/* Set Email Subject */
$email->Subject = 'NC Case: '. ''. $bean->name . ' '. ' is pending review';
/* Send email to users of Raised by department */
foreach($r_user_address as $uemail){
$email->addAddress($uemail);
}
/* Send email to Quality System Manager */
$email->addaddress($rev_email);
/* Create email message using email template */
$email=createNCEmailwithAction($email,$action_array,$bean,$xtpl);
} else if (strcasecmp ($nc_status,'Closed')==0){
/* Set Email Subject */
$email->Subject = 'NC Case: '. ''. $bean->name . ''. ' is Closed';
/* Send email to users of Raised by department */
foreach($r_user_address as $uemail){
$email->addAddress($uemail);
}
/* Send email to Issued to Department */
foreach($address as $iemail){
$email->addAddress($iemail);
}
/* Create email message using email template*/
$email=createNCEmailwithAction($email,$action_array,$bean,$xtpl);
} else{
If ($bean->fetched_row['description'] != $bean->description){
/* Set Email Subject */
$email->Subject = 'NC Case: ' .''. $bean->name .''. ' has been modified';
/* Create email message using email template */
$email=createNCEmailwithAction($email,$action_array,$bean,$xtpl);
/* Build appropriate email list */
foreach($address as $uemail){
$email->addAddress($uemail);
}
/* Send email to Quality System Manager */
$email->addaddress($rev_email);
}
}
}
关系名称很棘手!我总是弄错它们所以这里有一个片段可以让你找到确切的名字
$m1 = 'Users';
$m2 = 'ACLRoles';
print_r(getRelationshipByModules($m1, $m2));
$m2 = 'Users';
$m1 = 'ACLRoles';
print_r(getRelationshipByModules($m1, $m2));
请注意顺序很重要所以这就是我重复这句话两次但顺序不同的原因。
为您想知道关系名称的模块更改 m1/m2,然后执行 get_linked_beans
我正在 suitecrm 中设置一个逻辑挂钩,以允许将 nc 案例通过电子邮件发送给提出问题的部门;我不断收到错误消息“无法在 NC 发布到的部门内找到用户;表明 dept_array 等于零。我要使用 getbeans 和关系 tables。我创建了关系dept_department_nccas_nc_case 在 suitecrm 中,但 table 中没有数据,所以我想知道是不是这个原因,还是我的语法不正确。
class nc_email_notification {
public function email_notification(&$bean, $events, $arguments){
/*define 'review_pending' as string constant */
/*Get sugar email engine*/
$email = new SugarPHPMailer();
$email->From = 'suitecrm@gmail.com';
$email->FromName ='SuiteCRM';
/*Get the Department NC was Issued to */
$dept_array= $bean->get_linked_beans('dept_department_nccas_nc_case','dept_Department_sugar');
if(count($dept_array)==0){
/*log error*/
$GLOBALS['log']->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['log']->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['log']->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['log']->fatal("Could not find Users within the department NC is raised by: ". $bean->name);
}
else {
$r_user_address = getDepartmentUsersEmail($raised_user_array);
}
}
/*Get the Quality Systems Department*/
//$qual_dept=$dept_array[0]->retrieve)by)string_fields(array('name' => 'Quality Systems' ));
//$qual_dept->load_relationship('dept_department_email_addresses_primary');
/* Send email to Manager */
$rev_email = 'ramon@gmail.com';
/*Get NC Action for the NC Case*/
$action_array = $bean->get_linked_beans('nccas_nc_case_ncact_nc_action','ncact_NC_Action_sugar');
/* Get sugar template engine */
$xtpl = new XTemplate("XTemplate/NCEmailTemplate.html");
/*GEt the URL for the NC Case */
$url = $GLOBALS['sugar_config']['site_url'].'index.php?module=ncase_NonConformance&action=DetailView&record='.$bean->id;
$xtpl -> assign('URL', $url);
/* Get NC Status */
$nc_status=trim($bean->getFieldValue('status'));
/* Get NC ID */
$id = $bean->getFieldValue('id');
if(empty($bean->fetched_row['id'])){
$email=createNCEmail($email,$rev_email,'New NC Email Notification',$bean,$xtpl);
/* Send email to Quality System Manager */
$email->addaddress($rev_email);
/* Send email to users of Issued to department */
foreach($address as $uemail){
$email->addAddress($uemail);
}
}else {
if (strcasecmp ($nc_status,'review_pending')==0){
/* Set Email Subject */
$email->Subject = 'NC Case: '. ''. $bean->name . ' '. ' is pending review';
/* Send email to users of Raised by department */
foreach($r_user_address as $uemail){
$email->addAddress($uemail);
}
/* Send email to Quality System Manager */
$email->addaddress($rev_email);
/* Create email message using email template */
$email=createNCEmailwithAction($email,$action_array,$bean,$xtpl);
} else if (strcasecmp ($nc_status,'Closed')==0){
/* Set Email Subject */
$email->Subject = 'NC Case: '. ''. $bean->name . ''. ' is Closed';
/* Send email to users of Raised by department */
foreach($r_user_address as $uemail){
$email->addAddress($uemail);
}
/* Send email to Issued to Department */
foreach($address as $iemail){
$email->addAddress($iemail);
}
/* Create email message using email template*/
$email=createNCEmailwithAction($email,$action_array,$bean,$xtpl);
} else{
If ($bean->fetched_row['description'] != $bean->description){
/* Set Email Subject */
$email->Subject = 'NC Case: ' .''. $bean->name .''. ' has been modified';
/* Create email message using email template */
$email=createNCEmailwithAction($email,$action_array,$bean,$xtpl);
/* Build appropriate email list */
foreach($address as $uemail){
$email->addAddress($uemail);
}
/* Send email to Quality System Manager */
$email->addaddress($rev_email);
}
}
}
关系名称很棘手!我总是弄错它们所以这里有一个片段可以让你找到确切的名字
$m1 = 'Users';
$m2 = 'ACLRoles';
print_r(getRelationshipByModules($m1, $m2));
$m2 = 'Users';
$m1 = 'ACLRoles';
print_r(getRelationshipByModules($m1, $m2));
请注意顺序很重要所以这就是我重复这句话两次但顺序不同的原因。
为您想知道关系名称的模块更改 m1/m2,然后执行 get_linked_beans