I am attempting to use an after save logic hook to scrub bogus email addresses that are entered during testing, etc. However, the email address does not update. Below is the code I am using. I am currently on 6.5 enterprise. Does anyone have an idea of what I may be doing wrong? Or, how to correctly update / remove an email address through an after save logic hook?
Thanks!
$sea = new SugarEmailAddress;
$sea = $bean->emailAddress;
foreach ($bean->emailAddress->addresses as $k=>$emailaddress ) {
if( $ema = $emailaddress['email_address'] ) {
if(
stripos($ema,'#none.com') !== FALSE ||
stripos($ema,'#test.com') !== FALSE ||
stripos($ema,'#nunya.com') !== FALSE ||
stripos($ema,'#testing.com') !== FALSE
) {
$sea->addresses[$k]['emailaddress'] = '' ;
//sugar_die(print_r($sea->addresses));
$sea->save($bean->id,$bean->module_dir);
}
}
}
To update user's email address in logic hook or custom import you can use below logic:
if($bean->email1) {
$sea = new SugarEmailAddress();
// Add a primary email address
$sea->addAddress($bean->email1, true);
// Associate the email address with the given module and record
$sea->save($user_id, "Users");
}
Related
I'm now able to only have an email sent when a cell in one sheet has something added to it and not when that thing is deleted. However, it only triggers an email when I manually add a value and not when a value is added via the appsheet it's linked to. I know it's possible because when I was playing around with it yesterday I could get emails to trigger from my phone via the appsheet, but now it only works if I type something random in a cell and press enter. I just can't see what might be wrong with this. Can anyone please help? Thank you!
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet4=ss.getSheetByName('Copy');
var emailAddress = sheet4.getRange(2,12).getValue();
var subject = sheet4.getRange(2,13).getValue();
var message = sheet4.getRangeList(['G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8'])
.getRanges()
.map(range => range.getDisplayValue())
.join('\n');
MailApp.sendEmail(emailAddress, subject, message);
}
function onEdit(e) {
if (e.source.getActiveSheet().getName() === `Trigger`) {
if (e.range.rowStart >= 1 && e.range.columnStart >= 1) {
if (`value` in e) sendEmail()
}
}
}
With AppSheet 'edits' you will have to use onChange().
Try:
function onChange(e) {
if (e.source.getActiveSheet().getName() === `Trigger`) {
if (e.source.getActiveRange().getRow() >= 1 && e.source.getActiveRange().getColumn() >= 1) {
if (e.source.getActiveRange().getValue() !== ``) sendEmail()
}
}
}
Note: This is specified to only work on an individual cell edit.
Let me know if this works for your AppSheet!
See:
Event Objects | onChange
After form submission , any number of refresh is storing the data that many times in the db.
ie. !empty($_POST) is always true after on submission.
How can I stop the submission without redirecting the page/url. As I want to stay in the same page.
I am using form_open() and form_submit() i codeigniter.
in view
<?php echo form_open("",array('method' => 'POST'));?>
/* form fields */
'Send', 'value' => 'Send Notifications',"name"=>"send_notification")); ?>
in controller
`if (!empty($_POST['send_notification'])) {
/* validation rules & data*/
if ($this->form_validation->run() == TRUE){
$this->model->insert($data);
}
}`
How can I stop the duplicate record insertion, I have tried , unset($_POST) , isset() , if($this->input->post()) , nothing seems to work.
Just do a redirect(); to the same age after the insert function.
This worked for me. It may help someone
Controller file :
public function success()
{
$_SESSION['txnid'] = $this->input->post('txnid');
$this->bind->set_order();
$this->load->view('success');
}
Model file :
public function set_order()
{
$txnid = $_SESSION['txnid'];
$qry = $this->db->query("SELECT * from orders where transaction_id = '$txnid'");
$result = $qry->result_array();
if($qry->num_rows() == 0 )
{
//add to database here
}
else
{
// do nothing
}
}
I am adding txnid to database on submit. So if it tries to resubmit, it checks if txnid already exist or not.
I am having trouble setting a text value in a custom field I added to the address form.
function fieldChanged_form(type, name) {
if (name == 'custentity_bsi_agycampus') {
var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
console.log("selected line " + lnSeq);
nlapiSelectLineItem('addressbook', lnSeq);
var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
nlapiSetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd', agency_campus, true, true);
console.log('agency' + ',' + agency_campus);
}
nlapiCommitLineItem('addressbook');
console.log('after commit: '
+ nlapiGetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd'));
}
}
This script(applied to the Customer Form under the custom code tab) will not set custrecord_bsi_agy_div_bur_sd with the text value from custentity_bsi_agycampus (a custom field in the customer form). However, if I change custrecord_bsi_agy_div_bur_sd to addr1 (a field that is a default in the address form), it works just like I'd like.
This leads me to wonder whether or not I can access my custom field in the address form through 'addressbook' like you can for all of the other address fields. Does anyone know the answer to that question or have an idea of how I can troubleshoot this issue?
I believe you need to work with addresses as subrecords. Play around with something patterned after this:
// {nlobjSubrecord} Get one of the addresses off the sublist
var subrecord = {};
nlapiSelectLineItem('addressbook', 1);
subrecord = nlapiEditCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
// Set the data on the subrecord
subrecord.setFieldValue('attention', 'Some Guy');
subrecord.setFieldValue('addr1', '1234 5th St');
subrecord.setFieldValue('addr2', 'Apt 234');
subrecord.setFieldValue('addrphone', '5558675309');
subrecord.setFieldValue('city', 'Scottsdale');
subrecord.setFieldValue('state', 'AZ');
subrecord.setFieldValue('country', 'US');
subrecord.setFieldValue('zip', '85260');
// Commit the subrecord to its parent before submitting the parent itself
subrecord.commit();
I am trying to include in the email notification to the submitter/user (person filling out the form) the form the data from the form that the put into the form.
I found this tutorial on including it in the email to myself as the owner of the form (http://www.labnol.org/internet/google-docs-email-form/20884/), and it works great, but I want to send that information to the person who filled out the form.
I have tried replacing this code:
var email = Session.getActiveUser().getEmail();
with this code:
var email = e.namedValues["Email Address"].toString();
That doesn't seem to be the trick. I double-checked the field name in the form/response spreadsheet, and it does match "Email Address." I also made that a required field in the form.
Could someone assist me with this?
you need to check the each column in iteration....
if the column is email - address column then you need to assign to email variable.
here you need to assign
for ( var keys in columns )
{
var key = columns[keys];
if(columns[keys] == "Email Address")
{
email = e.namedValues[key].toString();
}
if ( e.namedValues[key] && (e.namedValues[key] != "") )
{
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
}
I have a situation where I want a set of users (employees) to be able to create a node, but to replace the uid (user ID) with that of the users profile currently displayed.
In other words, I have a block that that calls a form for a content type. If an employee (uid = 20) goes to a clients page (uid =105), and fills out the form, I want the uid associated with the form to be the client's(105), not the employee's.
I'm using arg(1) to grab the Client's uid - here is what I have..
<?php
function addSR_form_service_request_node_form_alter(&$form, $form_state) {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$form['#submit'][] = 'addSR_submit_function';
}
}
function addSR_submit_function($form, $form_state) {
$account = user_load(arg(1));
$form_state['values']['uid'] = $account->uid;
$form_state['values']['name'] = $account->name;
}
?>
The form is loading in the block, but when submitted, is still showing the employee uid. I don't want to use hook_form_alter because I don't want to modify the actual form, because clients can fill out the form directly, in this case, I don't want to modify the form at all.
I'm also ashamed that I'm putting this in a block, but I couldn't think of a way to put this in a module, so any suggestions on that would also be appreciated...
To create your form in a block, you could use the formblock module. Especially if you are not used to use the Drupal API. Then all that's left if to add your own submit handler to the form. This is a piece of code that is run, when the form is submitted. You only want to do this on clients pages so you would do that using the hook_form_alter function.
/**
* Hooks are placed in your module and are named modulename_hookname().
* So if a made a module that I called pony (the folder would then be called
* pony and it would need a pony.info and pony.module file I would create this function
*/
function pony_form_service_request_node_form_alter(&$form, $form_state) {
// Only affect the form, if it is submitted on the client/id url
if (arg(0) == 'client' && is_numeric(arg(1))) {
$form['#submit'][] = 'pony_my_own_submit_function';
}
}
function pony_my_own_submit_function($form, &$form_state) {
$account = user_load(arg(1));
$form_state['values']['uid'] = $account->uid;
$form_state['values']['name'] = $account->name;
}
The idea behind this code, is to only alter the form when the condition is met - that it is submitted on a client page. I guessed that the arg(0) would be client so if it's something else you would need to change that of cause. We only need to add a submit function, since what we want is to change the values if the form has passed validation.
Then if that is the case our 2nd function is run, which does that actual alteration of the values.
PHP blocks are bad. You can put them in a module.
function hook_block($op, $delta = 0) {
// Fill in $op = 'list';
if ($op == 'view' && $delta = 'whatever') {
$account = user_load(arg(1));
$node = array('uid' => $account->uid, 'name' => $account->name, 'type' => 'service_request', 'language' => '', '_service_request_client' => $account->uid);
$output = drupal_get_form('service_request_node_form', $node);
// Return properly formatted array.
}
}
Additionally, you want a form_alter just to enforce the values. It's ugly but it works.
function hook_form_service_request_node_form_alter(&$form, $form_state) {
if (isset($form_state['node']['_service_request_client'])) {
$form['buttons']['submit']['#submit'] = array('yourmodule_node_form_submit', 'node_form_submit');
}
}
function yourmodule_node_form_submit($form, &$form_state) {
$account = user_load($form_state['node']['_service_request_cilent'])l
$form_state['values']['uid'] = $account->uid;
$form_state['values']['name'] = $account->name;
}