- Posts: 109
Use parameter in AddDays Heater
- JD Cox
- Topic Author
- Offline
- User
Less
More
3 years 4 months ago #3632
by JD Cox
Use parameter in AddDays Heater - Post(3632) was created by JD Cox
I'm using this .NET Script heater (Execute Per Row) and it seems to be working fine:
public object DoWork()
{
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
DateTime mydate = (DateTime)InValues[0].GetDateTime(); //order date
bool prior2 = (bool)InValues[1].GetBool(); //prior to 2pm
int myday = (int)mydate.DayOfWeek;
int ret = 1;
int days = 1;
switch (myday)
{
case 5: //friday add 3 days if after 2pm
if (prior2 == false)
ret = 3;
break;
case 6: //saturday add 2 days
ret = 2;
break;
}
//set flowheater parameter days to advance export date
Parameter["days"].Value = ret;
return null;
}
The problem is with the parameter $days$ in the number value field in the AddDays heater.
I get this error on the first row:
H: AddDays The value [$days$] could not be converted into a number.
If I'm unable to use the parameter in the AddDays heater would I be able to calculate the date add in the .NET heater and return that value?
public object DoWork()
{
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
DateTime mydate = (DateTime)InValues[0].GetDateTime(); //order date
bool prior2 = (bool)InValues[1].GetBool(); //prior to 2pm
int myday = (int)mydate.DayOfWeek;
int ret = 1;
int days = 1;
switch (myday)
{
case 5: //friday add 3 days if after 2pm
if (prior2 == false)
ret = 3;
break;
case 6: //saturday add 2 days
ret = 2;
break;
}
//set flowheater parameter days to advance export date
Parameter["days"].Value = ret;
return null;
}
The problem is with the parameter $days$ in the number value field in the AddDays heater.
I get this error on the first row:
H: AddDays The value [$days$] could not be converted into a number.
If I'm unable to use the parameter in the AddDays heater would I be able to calculate the date add in the .NET heater and return that value?
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
3 years 4 months ago - 3 years 4 months ago #3633
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic Use parameter in AddDays Heater - Post(3633)
Usually “Each row Heaters” should be executed before common heaters are processed. But in case you using conditions (
IF-THEN-ELSE Heater
) or for example
Set Parameter Heater
and this chain triggers the
AddDays Heater
the
FlowHeater Parameter
DAYS isn´t right initialized. In this case you´re always using the calculated DAYS from the previous record!
If modified your script, see below. Now the .NET Script Heater returns the calculated date. Please have a look to the attached example.
C# .NET AddDays script example
If modified your script, see below. Now the .NET Script Heater returns the calculated date. Please have a look to the attached example.
C# .NET AddDays script example
Code:
public object DoWork()
{
if (InValues.Length == 0)
throw new ArgumentException("min. 1 input parameters expected!");
DateTime mydate = (DateTime)InValues[0].GetDateTime(); //order date
bool prior2 = (bool)InValues[1].GetBool(); //prior to 2pm
int myday = (int)mydate.DayOfWeek;
int ret = 1;
int days = 1;
switch (myday)
{
case 5: //friday add 3 days if after 2pm
if (prior2 == false)
ret = 3;
break;
case 6: //saturday add 2 days
ret = 2;
break;
}
return mydate.AddDays(ret);
}
Best wishes
Robert Stark
Last edit: 3 years 4 months ago by FlowHeater-Team.
Please Log in or Create an account to join the conversation.
- JD Cox
- Topic Author
- Offline
- User
Less
More
- Posts: 109
3 years 4 months ago #3634
by JD Cox
Replied by JD Cox on topic Use parameter in AddDays Heater - Post(3634)
Thanks Robert,
The .NET Script got me where I needed to be.
JD
The .NET Script got me where I needed to be.
JD
Please Log in or Create an account to join the conversation.
Time to create page: 0.269 seconds