Hi,
My rule script on C# defaulting field value as "A" in case left blank or multiple selected, is as below:
using System;
Context.Field("SundayLunchOptions1");
{
int counter =0;
if (Convert.ToBoolean(Context.Field("A").Value) == true) { counter++; }
if(Convert.ToBoolean(Context.Field("B").Value) == true) { counter++; }
if(counter ==0)
{
Context.Field("A").Value = true;
Context.Field("B").Value = false;
}
if(counter >1)
{
Context.Field("A").Value = true;
Context.Field("B").Value = false;
}
}
When I check, I receive the following error on my Script rule:
Script:System.InvalidCastException: Object cannot be cast from DBNull to other types. at System.DBNull.System.IConvertible. ToBoolean(IFormatProvider provider) at Main. Execute(IRuleContext Context)
Can you please help?
Comments
0 comments
Please sign in to leave a comment.