CakePHP saveField NULL value in a INT column - cakephp

I want to update one column which is an INT with a NULL value. I'm using CakePHP 2.3 with the saveField('field', 'value') method.
Here is my code :
$this->Customer->id = $customer_id;
if ($this->Customer->saveField('account_id', 'NULL')) {
//Do some stuff
}
So when I put 'NULL', the row is updated to 0. I tried NULL without quotes and the row is not updated.
EDIT :
The field in the db accepts NULL value.
Do you have any idea ?
Thanks

Do not pass 'NULL' as a string but as null value:
if($this->Customer->saveField('account_id', null))
{
//do some stuff
}
else
{
//do you get anything here ?
debug($this->Customer->validationErrors);
}

I've had a similiar problem caused by a Upload Behaviour that had validations preventing the saving. Check your models, it might help. I assume saveField returns true even when validation rules prevent saving.

Related

Yes and No as the output for the condition in logic App

I have a simple requirement , In logic app trigger I am getting a variable called suspendschedule and I want to make
if(suspendschedule == true then value should be Yes
if suspendschedule == false then the value should be No
and this is what I am trying
#if(equals(triggerBody()?['_suspendschedule],"false"),"No","Yes")
if your suspendschedule is a type of bool then Try these
first, check for the true condition because if the field is null or missing in triggerBody it will go in else
#if(equals(triggerBody()?['suspendschedule'],bool(1)),'Yes','No')
if it is in string format or you are not sure try this it will check both bool and string
first, check for the true condition because if the field is null or missing in triggerBody it will go in else
#if(equals(triggerBody()?['suspendschedule'],'true'),'Yes','No')

how to filter data from array and apply conditions angular8

I am getting below sample data from api dynamically.
Can anyone suggest how to apply condition based on data.
You need to check values in array
if (this.tagSchemaDetails.schema_context.providers.indexOf('All') < 0) {
request['schema_context'] = this.createConditionsData();
}
As your providers is array of string and you are just comparing that with string so in all cases it will validate the condition.
So you have to check the strings in the array and compare them with 'All' to properly check the condition.
So your code should look like this:
if(!this.tabSchemaDetails.schema_context.providers.includes('All')){
request['schema_context']=this.createConditionsData();
}
as others have said here, you have to check values in the "providers" array. since you just need to check provider != 'All' you can simply check for the first element in the array as below.
if (this.tagSchemaDetails.schema_context.providers[0] !== 'All') {
request['schema_context'] = this.createConditionsData();
}

Can't update Boolean value in Apex

I cannot update update this Boolean value in Apex. What is going wrong? The if statement, and the fact that the front end representation is a checkbox, proves that it is indeed a boolean value. I am new to Apex so I feel its a basic misunderstanding of how it works. Can anyone help me out?
Here is the code that I'm executing in an Anonymous Window.
Account acc = new Account(Name='Test Name');
if (acc.Do_Not_Contact__pc == false) {
System.debug('DNC is false');
} else {
System.debug('DNC is true');
}
insert acc;
acc.Do_Not_Contact__pc = true;
update acc;
It fails on the second to last line, displaying the following message:
System.DmlException: Update failed. First exception on row 0 with id 001W000000fFiVbIAK; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Do_Not_Contact__pc: [Do_Not_Contact__pc]
What's particularly frustrating is that when I change the second to last line to
acc.Do_Not_Contact__pc = 'true';
I get an error stating that I cannot assign a String to a Boolean value
Remove the single quotes and I assume you typed the field name wrong. Try acc.Do_Not_Contact__c = true;

Cakephp - how check row is null?

I want to set flash message if there's not fullfilled row "surname" in database. How can I check if row surname is null ?
I tried to make something like this:
if(!isset(['User']['surname'])
or
if($user(['User']['surname']) === NULL
it obviously doesnt work
You can check it like.
<?php
if(!isset($user['User']['surname']) || empty($user['User']['surename'])){
// your code goes here
}
if(empty($user['User']['surname'])) {
// your code goes here
}
you can check like this
if(isset($user['surname']) || empty($user['surname'])){
$this->Session->setFlash('No Data.');
}

EXTJS Store issue with Null Values -- useNull: doesn't have an affect --Help?

Folks,
I have a combobox component backed by a JSONStore. The data loaded into the store is returning null for the combobox's value. The value is an int. The JSON decode process is converting the null value into a zero; causing the combobox to fail to render when it attempts to find the pk, zero that doesn't exist in its backing store.
I've found the useNull: config option for data.Field objects, upgraded to 3.3.0 Final and set my int value for the combobox to useNull:true. This isn't having any affect at all, unfortunately. The decoded value is still being changed from null to zero.
Any ideas about how to not set the field to a zero when the data for a JSON field is null?
Here's a pic of what's going on. Notice the data: value is zero, but the JSON value is null.
Thanks!
(gah! stoopid reputation < 10 so I can't directly post the pic. View it here: debug pic )
Also, here's my store's field config:
fields: [
{name:"id", type:"int"},
{name:"occurenceDate", dateFormat: 'Y-m-d\\TH:i:s', type:"date"},
{name:"docketNumber", type:"string"},
{name:"courtLocationId", type:"int", useNull:true},
{name:"assignedOfficerId", type:"int", useNull:true},
{name:"primaryIncidentTypeId", type:"int", useNull:true},
{name:"secondaryIncidentTypeId", type:"int", useNull:true},
{name:"tertiaryIncidentTypeId", type:"int", useNull:true},
{name:"incidentLocation", type:"string"},
{name:"summary", type:"string"},
{name:"personalItemsSeized", type:"string"},
"supplements",
"parties",
"judgeIds"
]
Try using it without type declaration. You may also use convert method:
{
name: "primaryIncidentTypeId",
convert: function(value, row) {
return (value == null) ? null : parseInt(value);
}
}
About the combo width: I usually use
defaults: {
anchor: '100%'
}
in the form declaration and have no problems with widths.
Isnt't it possible to provide convert functions from server side together with all other metadata?
And I'm still using ExtJS 3.2 - no need of any new bugs in the production systems :)
This also got me, you can additionally override the type convert function in Ext.data.Types to allow null values for integer type fields.
Ext.data.Types.INT.convert = function(v){
v = parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10);
return isNaN(v) ? null : v;
};
You must use defaultValue: null ,useNull : true because default value for integet type is zero
Example:
{name:"primaryIncidentTypeId", type:"int", useNull:true , defaultValue: null },

Resources