@DoShawhan Code looks good to me and it should work like when we uncheck it should be NULL as per the code.
ContractExtDS.ursInstalled is bool? (nullable), but you try to cast it to bool.
Try to check it in this way:
if (e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row) as bool? == true)
@DoShawhan Little bit modified but nothing much difference. Below code will help you debug and check what value we are fetching.
protected void _(Events.FieldUpdated<ContractExtDS.usrInstalled> e)
{
var row = e.Row;
if (row != null)
{
ContractExtDS rowExt = row.GetExtension<ContractExtDS>();
//I don’t think that it is getting past this line, but I can’t figure it out
if (rowExt.usrInstalled == true)
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(row, DateTime.Now);
}
else
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(row, null);
}
}
}
I assume you do not want it based on the business date, but the current date. DateTime.Now does not modify based on timezone, and can get messed up in the database when loading. Instead of DateTime.Now and DateTime.Today in Acumatica, you should use PX.Common.PXTimeZoneInfo.Now or PX.Common.PXTimeZoneInfo.Today
So the line would be:
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(row, PX.Common.PXTimeZoneInfo.Now);
@DoShawhan - I must be reading this wrong because no one else has mentioned it, but your expression looks backwards to me.
I think if you remove the ‘!’ it would be correct, according to your description of wanting to set the value when the checkbox is checked.
if((bool)(e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row)))
@DoShawhan - I must be reading this wrong because no one else has mentioned it, but your expression looks backwards to me.
I think if you remove the ‘!’ it would be correct, according to your description of wanting to set the value when the checkbox is checked.
if((bool)(e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row)))
I tried this, but I don’t think that the event is being triggered, because I put
throw new PXException("here");
and the exception was never thrown. Also, when I save the project, the checkbox reverts back to how it was before I checked it.
I tried this, but I don’t think that the event is being triggered, because...the exception was never thrown.
Did you place the exception here, so that it would fire no matter what the condition evaluated to?
protected void _(Events.FieldUpdated<ContractExtDS.usrInstalled> e)
{
var row = e.Row;
throw new PXException("here");
//I don’t think that it is getting past this line, but I can’t figure it out
if((bool)(e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row)))
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(row, DateTime.Now);
}
else
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(row, null);
}
}
If that’s the case, and it’s still not firing, perhaps try unpublishing all packages, republishing, and restarting the application, or maybe someone else has an idea.
@DoShawhan - I must be reading this wrong because no one else has mentioned it, but your expression looks backwards to me.
I think if you remove the ‘!’ it would be correct, according to your description of wanting to set the value when the checkbox is checked.
if((bool)(e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row)))
I tried this, but I don’t think that the event is being triggered, because I put
throw new PXException("here");
and the exception was never thrown. Also, when I save the project, the checkbox reverts back to how it was before I checked it.
Hi @DoShawhan
Did you set the checkbox “CommitChanges” property to true?
Hi @DoShawhan
Did you set the checkbox “CommitChanges” property to true?
No, I had not. However, the false statement is working but I cannot get the true part of the if statement to run when the checkbox is checked. I have got an error that says “object cannot be converted to Boolean.“ Does anyone know what the object looks like that this
e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row)
returns?
Thanks
Cast it as a nullable boolean (bool?)
Have you tried this?
if (e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row) as bool? == true)
Hi @DoShawhan
As everybody you can also try this way:
if((e.Cache.GetValueExt<ContractExtDS.usrInstalled>(row) ?? false) == true)
Cast the newvalue set to a bool? and try that.
protected void _(Events.FieldUpdated<ContractExtDS.usrInstalled> e)
{
bool? installed = (bool?)e.NewValue;
if (installed == true)
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(e.Row, PX.Common.PXTimeZoneInfo.Now);
}
else
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(e.Row, null);
}
}
Cast the newvalue set to a bool? and try that.
protected void _(Events.FieldUpdated<ContractExtDS.usrInstalled> e)
{
bool? installed = (bool?)e.NewValue;
if (installed == true)
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(e.Row, PX.Common.PXTimeZoneInfo.Now);
}
else
{
e.Cache.SetValueExt<ContractExtDS.usrInstallationCompletedDate>(e.Row, null);
}
}
This worked!
Thanks