I am using drupal and I have webform where there is field date of production and there is calendar in this field When I put date 2020-09-30 in this field and submit my form it save this field wrongly in salesforce like this:
6/9/2022 it changed to year 2022 and also changed month and day
following is the condition I have put in salesforce function
function ublox_salesforce_salesforce_webforms_save_submission_alter(&$fields, $context) {
foreach ($fields as $key => $value) {
if (in_array($key, ["Date_Prototype__c", "Date_Production__c", "NBIOT_Date_of_Field_Trial__c", "NBIOT_Date_Lab_Trial__c"])) {
$fields[$key] = trim($value);
if ($fields[$key] == 'Date_Production__c') {
$fields[$key] = format_date(strtotime($fields['Date_Production__c']), 'medium', 'm-d-Y');
}
}
You can see my if condition for 'Date_production__c' ( date of production start )
Where I am doing wrong? I am unable to find solution anyone can help me please.
I have also attached the screenshot of my field where I have put date 2020-09-30 but it reached differently like 6/9/2022
Thanks in advance
What's the outcome of this format_date(strtotime($fields['Date_Production__c']), 'medium', 'm-d-Y');, can you write it to log or echo or something?
Salesforce API expects dates in 2020-09-14 format (so that'd be Y-m-d?) and datetimes in 2020-09-14T18:07:30Z format. See https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
Related
EDIT:
I want to thanks #jimmix for giving me some idea to get started on my last post, But unfortunately, my post was put on hold. Due to the lack of details.
But here are the real scenario, I'm sorry if I didn't explain well my question.
From my CSV file, I have a raw data, then I will upload using my upload() function in into my phpmyadmin database with the table name "tbldumpbio",
See the table structure below:(tbldumpbio)
From my table tbldumpbio data, I have a function called processTimesheet()
Here's the code:
public function processTimesheet(){
$this->load->model('dbquery');
$query = $this->db->query("SELECT * FROM tbldumpbio");
foreach ($query->result() as $row){
$dateTimeExplArr = explode(' ', $row->datetimex);
$dateStr = $dateTimeExplArr[0];
$timeStr = $dateTimeExplArr[1];
if($row->status='C/Out' and !isset($timeStr) || empty($timeStr) ){
$timeStrOut ='';
} else {
$timeStrOut = $dateTimeExplArr[1];
}
if($row->status='C/In' and !isset($timeStr) || empty($timeStr) ){
$timeStrIn ='';
} else {
$timeStrIn = $dateTimeExplArr[1];
}
$data = array(
'ID' => '',
'companyAccessID' => '',
'name' => $row->name,
'empCompID' => $row->empid,
'date' => $dateStr,
'timeIn' => $timeStrIn,
'timeOut' => $timeStrOut,
'status' => '',
'inputType' => ''
);
$this->dbquery->modInsertval('tblempbioupload',$data);
}
}
This function will add another data into another table called "tblempbioupload". But here are the results that I'm getting with:
Please see the below data:(tblempbioupload)
The problem is:
the date should not be duplicated
Time In data should be added if the status is 'C/In'
Time Out data should be added if the status is 'C/Out'
The expected result should be something like this:
The first problem I see is that you have a time expressed as 15:xx:yy PM, which is an ambiguous format, as one can write 15:xx:yy AM and that would not be a valid time.
That said, if what you want is that every time the date changes a row should be written, you should do just that: store the previous date in a variable, then when you move to the next record in the source table, you compare the date with the previous one and if they differ, then you insert the row, otherwise you simply progress reading the next bit of data.
Remember that this approach works only if you're certain that the input rows are in exact order, which means ordered by EmpCompId first and then by date and then by time; if they aren't this procedure doesn't work properly.
I would probably try another approach: if (but this is not clear from your question) only one row per empcompid and date should be present, i would do a grouping query on the source table, finding the minimum entrance time, another one to find the maximum exit date, and use both of them as a source for the insert query.
I have a project that I need to finish before July, it's for school.
It was all going well until I started having problems with an array that comes from my database.
Please keep in mind that this is my first time with PHP and I'm learning as I am doing:
My database has a table named "Pessoas" and another named "Pessoas_Pessoas". The second was to keep the record of relationships between entries on the "Pessoas" table ( for example, if the ID 1 had a relationship with the ID 2, the information would be kept on "Pessoas_Pessoas" ).
The tricky part is that I am supposed to use PHP to prevent the user from duplicating a relationship.
A good example would be Facebook's friend system:
If I would be friend's with John, it wouldn't appear his profile on the "People you might know" section.
Since I am using MVC and Slim Framework, I managed to get what I want from the database on the model, but I have this problem on the Controller:
This is an image from the table "Pessoas_Pessoas", being id_PessoasA the id of the profile being visualized and id_PessoasB the id of the profile I'm trying to make a relationship with
I managed to get 5 profiles to test this feature and I managed to get those relationships as well, but the problem is that when I try to verify if the id of each profile is the same has id_PessoasB to then unset from the array, but it only works one time even if the condition is true. Here's the code:
foreach ($resultadoRelacao as $key => $value) {
foreach ($resultadoRelacao0 as $key0 => $value0) {
if ($value0['id'] == $value['id_PessoasB']) {
$indice = array_search($value0['id'], $resultadoRelacao0);
unset($resultadoRelacao0[$indice]);
}
}
}
Thanks for your time and please ask anything if needed. I'm not really sure what's needed anymore, I'm stuck for 2 weeks.
As you are using the foreach() to go through the array and you have matched the element against the one your looking for, you can then use the key value (in this case $key0) of the foreach() to remove the element your currently looking at...
foreach ($resultadoRelacao as $key => $value) {
foreach ($resultadoRelacao0 as $key0 => $value0) {
if ($value0['id'] == $value['id_PessoasB']) {
unset($resultadoRelacao0[$key0]);
}
}
}
foreach ($resultadoRelacao as $key => $value) {
foreach ($resultadoRelacao0 as $key0 => $value0) {
if ($value0['id'] == $value['id_PessoasB']) {
if(($indice = array_search($value0['id'], $resultadoRelacao0)) !==false){
unset($resultadoRelacao0[$indice]);
}
}
}
}
webform_get_submissions() in Drupal 7 return all the Webform submissions, the problem is that I want to return the submission that falls between 2 date
ex:
get webform submissions that have been submitted between 16 April 2018 and 28 April 2018.
Let me share a workaround that I came up with, maybe it will help you to find a full-size solution.
You actually can use a filter in the function webform_get_submissions not only by nid or sid but apparently by any other field. In this case, there is possible to use a filter by a field named submitted:
$submissions = webform_get_submissions(array('nid' => $node->nid, "submitted" => "1503753434"));
It will result in recieiving a submission which field submitted is exactly equal to 1503753434. To get all submissions which are, for example, newer than 1503753434 one way is inside a file includes/webform.submissions.inc for the function webform_get_submissions_query change this part:
foreach ($filters as $column => $value) {
$pager_query->condition($column, $value);
}
to this part:
foreach ($filters as $column => $value) {
if ($column == "submitted") {
$pager_query->condition($column, $value, ">");
} else {
$pager_query->condition($column, $value);
}
}
This would result in getting submissions which are newer than 1503753434. By analogy we can add < filter or any other filters.
The problem with this workaround is that it requires to change a source file of Drupal and also it requires implementing a simple parsing by hand in case we want to have several conditions for one field name.
I have trouble saving my date and time values. I tried different formats, here the actual try.
validator in my form:
$datum=$this->CreateElement('text','datum')
->setAttrib('size', '10')
->addValidator(New Zend_Validate_Date('MM-DD-YYYY'));
$zeit=$this->CreateElement('text','zeit')
->setAttrib('size', '10')
->addValidator(new Zend_Validate_Date(array('format' => 'H:i:s')));
Snippet of my Controller addAction
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$logenr = $this->_getParam('kopfnr', 0);
$kopfnr = $logenr;
$dat= $form->getValue('datum');
$zeit = $form->getValue('zeit');
$thema = $form->getValue('thema');
$aktermine = new Application_Model_DbTable_Aktermine();
$aktermine->addTermine( $kopfnr, $dat, $zeit, $thema);
And, my add function in my database class:
public function addTermine($kopfnr, $datum, $zeit, $thema)
{
$data = array(
'kopfnr' => $kopfnr,
'datum' => $datum,
'zeit' => $zeit,
'thema' => $thema,
);
$this->insert($data);
}
I´m using a mySQL database on a WAMP installation.
Where is my error? As a remark I want to say, I get a new record, the value of "thema" and the keys are properly saved, so I think it must be some format thing somewhere.
EDIT: I get a new record but the fields date and time are empty. I get no errors
NEW: I added a debug test in my controller to see what comes for the date value, here is the answer:
string '01-04-2016' (length=10)
(I put in 01-04-2016)
By reading your comments I understand you have two problems. The first one is putting the date into your table and the second is to let the user use the normal date format (dd/mm/yyyy).
First problem is solved when you reformat the user input before putting it into the database.You can add the following line into the $form->isValid($formData) part:
$dat = (new DateTime($form->getValue('datum')))->format('Y-m-d');
This oneliner will convert the date from 'dd-mm-yyyy' to 'yyyy-mm-dd'.
thanks, after the suggestion to debug I changed the format of my date like this: $test1=date('Y/m/d',strtotime($dat));
And now it works!
Again I find myself at the mercy of the stackoverflow community!
I've gone over to use CodeIgniter for my PHP projects and it's been a breeze so far, hoever I've gotten stuck trying to update a database field with some post data.
My array is the usual: array(name => value, name => value, name => value);
which again is populated from the submitted $_POST data.
Similarly to the array, I have a database table with 2 fields: setting and value, where the names under setting corresponds to the array keys and value to the array keys' value.
(Did I explain that right?)
Nonetheless, I've been trying for a little while now to get this to work as it should, but, I'm really just waving my hands around in the dark.
I hope some of you bright minds out there can help me with this annoying issue!
Edit:
Thanks to everyone who replied! I managed to produce the result that I wanted with the following code:
foreach ($form_data as $key => $val)
{
$this->db->where ('setting', $key);
$this->db->set ('value', $val);
$this->db->update ('recruitment');
}
Now, I tried following up with this by adding:
if ($this->db->affected_rows() >= '1') { return true; }
return false;
To my model, and
if ($this->RecruitmentSettings->Update($form_data) == TRUE)
{
redirect('recruitment/success');
}
to my controller, but it's not working as expected at all. Any ideas what I'm doing wrong?
There are a lot of questions here. Do you already have values in the database and you want to update them? Or do you want to put in new data every time? The answer depends on that.
What you want is the insert_batch() or update_batch() methods of the active record class (if that's what you're using for the db).
foreach($post_array as $key => $value)
{
$settings[] = array(
'setting' => $key,
'value' => $value
);
}
$this->db->insert_batch('your_db_table', $settings);
OR, for updates:
$this->db->update_batch('your_db_table', $settings, 'setting');
You could do a query to check for settings and do insert_batch or update_batch depending on if there are results. If you wanted to insert every time, you could delete the rows in the table before you do the insert. I wouldn't do that without a transaction, however.
So you want to store the array data in the database? You could do this
Model
foreach ($data as $key => $item)
{
$this->db->set ('setting', $key);
$this->db->set ('value', $item);
$this->db->insert ('table_name');
}
return ($this->db->affected_rows() > 0);
Controller
if ($this->RecruitmentSettings->Update($form_data))
{
redirect('recruitment/success');
}
else
{
echo "error";
}