Committing updated record to database from a report form

Our Shipping/Receiving folks would like a timestamp in the Sales Order Pick List form so that they can see if/when an order’s pick list has been printed. I slapped together a small script to set OrderHed.UserDate1 to the current date/time when a user clicks the Print Preview button:

private void SOPickListForm_AfterToolClick(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
{
if (args.Tool.Key ==“PrintPreviewTool”)
{
EpiDataView edvOrderHed = (EpiDataView)oTrans.EpiDataViews[“OrderHed”];
edvOrderHed.CurrentDataRow[“UserDate1”] = DateTime.Now;
oTrans.NotifyAll();
oTrans.Update();
}
}

On the surface, this script appears to work: I added a textBox for the field, which populates with DateTime.Now when I click print preview. However, it doesn’t commit this data to the database, and the next time I pull that order in the report form UserDate1 is blank again. How do I force this thing to actually save the timestamp?

Use Begin / EndEdit or RowMod to let the EpiDataView know that there is a Dirty Row
such as

EpiDataView edvOrderHed = (EpiDataView)oTrans.EpiDataViews[“OrderHed”];
edvOrderHed.dataView[edvOrderHed.Row].BeginEdit();
edvOrderHed.dataView[edvOrderHed.Row]["UserDate1"]=DateTime.Now;
edvOrderHed.dataView[edvOrderHed.Row].EndEdit();
oTrans.Update();
4 Likes

That sounds like it totally SHOULD work, but it doesn’t seem to. :confused: No noticable difference.

In-transaction data directive BPM on ice.sysagenttask perhaps?

CONDITION:
Where taskdesc= the name of the report
and submituser = particular Epicor user OR a member of a particular security group OR just ignore this

ACTION:
update OrderHed.UserDate1 any way you want.

NOTE: will decrease all background processing performance by some number greater than 0 seconds (though, likely less than the 100ms for all processes except the one where the condition is met).

EDIT: actually wouldn’t have to be in-transaction–could be standard.

1 Like

The SysAgentTask table in our DB only has one row in it (and it’s not related to this report), but Ice.Systask DOES have a record for each time I generate an SO Pick List report. And I can link that table to Ice.SysTaskParam to get the Order List, which would theoretically link the task to the OrderHed records I want to update UserChar1 on. I wrote the following script in a standard data directive on Ice.SysTask:

foreach (var ttSysTaskRow in ttSysTask.Where(ttSysTaskRow => ttSysTaskRow.TaskDescription == “SO Pick List”))
{
foreach (var SysTaskParam_iterator in Db.SysTaskParam.Where(SysTaskParam_Row=> SysTaskParam_Row.SysTaskNum == ttSysTaskRow.SysTaskNum && SysTaskParam_Row.ParamName == “OrderList”))
{
foreach (var OrderHed_iterator in Db.OrderHed.Where(OrderHed_row=>SysTaskParam_iterator.ParamCharacter.Contains(OrderHed_row.OrderNum.ToString())))
{
OrderHed_iterator.UserDate1 = DateTime.Today;
}
}
}

This does not return any errors, but it also does not update the UserDate1 field. I’m not really surprised, since most of my syntax is guesswork. Does anyone see any screwups in my code?

Also, I noticed that for Standard directives the “Execute Custom Code” has a “With Rule” setting, which lets me choose between “Once passing all matching rows” or “once passing all existing rows.” I left it on the default setting (all matching rows) because I don’t really get what it does.

@josecgomez , you mentioned using RowMod to get the EpiDataView’s attention. How does that work? What’s the syntax?

I haven’t read through all of the post here so I don’t know the context but in general you can use:
RowMod = “A” (Added)
RowMod = “U” (Updated)
RowMod = “D” (Deleted)

So do I manually set the rowmod to U at the beginning of my code, to tell it to update? Do I call it like a normal field? I slapped this line into my code:

edvOrderHed.CurrentDataRow[“RowMod”] = “U”;

but it didn’t have any noticeable impact.

Is this in a post processing directive? If so, I don’t think you can update

Also, there may be a RowMod = “M” for modified, I can’t recall

grumble mumble Magic strings and constants grumble

IceRow.ROWSTATE_ADDED
IceRow.ROWSTATE_DELETED
etc

:wink:

1 Like

Haha bout time you set us straight.

Reminds me of this:

1 Like

Silly question, have you placed any debug statements to ensure something is happening in those foreach loops?

Chris, I just added PublishInfoMessage commands for every loop to see if any popped up. None did. :face_with_raised_eyebrow: Does anything in my code (posted above) look wrong, like it wouldn’t fire?

Also Bart, how should I use IceRow.ROWSTATE_ADDED? That’s the syntax for a BPM, right? Do I type IceRow.ROWSTATE = IceRow.ROWSTATE_ADDED to set that value? I am very, very new to this.

I’d bet a nickel it’s an issue with a whereclause. If you had a messagebox in your outer most foreach and nothing happens, I’d start there since it feeds the rest.

Maybe remove the where clause (and any code that makes changes) to ensure that you can see your records in the ttTable. I’d make the message say the value of ttRecord.TaskDescription to ensure it says what you expect.

If NOTHING happens you arent firing your BPM.

pseudo-code

foreach(var row in ttSysTask)
{
 PublishMsg(row.TaskDescription)
}

Yup, the PublishInfoMessage in the foreach loop didn’t fire. I also tried commenting out the foreach loops and just running a PublishInfoMessage command instead. Still nothing. So does this mean a data directive on Ice.SysTask won’t work? Is there another option? I could get code to fire on a form customization, it just wouldn’t commit to the DB.

Should work. I use it

Looking at my screenshot begs another silly question. Is it enabled?

Also are there any conditions before your custom code block?

Yes it’s enabled (always worth checking :stuck_out_tongue: ) and I just added a condition for "TaskDescription field of the Added Row is equal to “SO Pick List” " and it still isn’t showing my message.

Can you screen shot your directive like I did above?

Sure, here:

And with NO condition, it would not fire?

Code is set to run Asynch right?
image

Here is a sample of my code in that directive:

string elapse = "?";
foreach (var rec in (from taskrow in ttSysTask
select taskrow))
{
elapse = (rec.EndedOn - rec.StartedOn).ToString();
}