BPM Triggered on Task Agent Schedule - Help Needed

I have a task scheduled that runs every 15 minutes and I want a DD BPM to trigger off of it. I have created an in-transaction DD under SysAgentSched. I have made a condition statement that looks for the description to match the name of the schedule I created and for a change to the next run from any to another. I have written up some C# code that should trigger whenever these conditions are met that will update an existing row of data in the UD02 table. Credit to this post for the idea:

The problem I’m having is that my code doesn’t seem to be writing at all. I have confirmed this code to write perfectly fine in another BPM. I have also tested to be sure that the schedule is working by assigning a task to it. Does anyone have some troubleshooting techniques that I can try?

DD Diagram:

image

C# Code:
/*START FLAG TOGGLE*/
var Flag = Db.UD02.Where( r =>r.Company == callContextClient.CurrentCompany && r.Key1== "string" && r.Key2== "string" && r.Key3=="string").Select( r =>r.CheckBox01).DefaultIfEmpty().FirstOrDefault();

if(Flag == true)
{
  
  using (var txScope = IceContext.CreateDefaultTransactionScope())
  {
     foreach(var UD02 in (from r in Db.UD02 where r.Company == Session.CompanyID select r))
     {
      UD02.CheckBox01 = false;
     }
     Db.Validate();
     txScope.Complete();
  }
}
/*END FLAG TOGGLE*/

Throw a Show Message widget between the condition and Exec Custom Code widgets, just to make sure that its even coming out of the TRUE port of the condition block.

1 Like

It doesn’t seem to be trigging on the data side even with the message boxes.

image

Not sure why, because I can clearly see the tables being updated. Should I try a Standard DD instead of an in transaction?

I went ahead and swapped over to a standard definition and changed the next change to last changed on. After doing this and setting up emails to pop up I get the email from the false side. Thanks @ckrusen for helping diagnose which side we were hitting! In addition I found that we were hitting the false side of the condition because of a typo.

Next problem. I have a variable set to check the condition of UD02.CheckBox01. I pull that by using the following code:

`Db.UD02.Where( r =>r.Company == callContextClient.CurrentCompany && r.Key1 == “string” && r.Key2 == “string” && r.Key3 == “string”).Select( r =>r.CheckBox01).DefaultIfEmpty().FirstOrDefault()’

The variable keeps coming back as false, even though it is absolutely set to true:

image

Is there something wrong with how I am assigning the variable?

Safe to assume that your use of "string" in the where clause is just a place holder so you don’t post sensitive info here?

1 Like

Actually, I have the strings there as that is what the only entry for UD02 has as its keys. Should I make them something different to be safe?

If your code to set the checkbox seems to work, I’d think what you’re using should be fine.

The only thing I can think of to look into, is the .DefaultIfEmpty().FirstOrDefault() ending of that expression.

I can’t say that I fully understand what the .DefaultIfEmpty() does. Is it for when there’s no matching record, or for when a record is found, but the value is null?

Also, doesn’t .DefaultIfEmpty() usually specify a value to use when it is empty? Like: .DefaultIfEmpty(1)

1 Like

You are correct on the default if empty. Its for when there is nothing there and we want there to be a value. As for the code to get the data from the check box its the exact same as what I use for most if not all of my other bpm’s that require data from other tables.

@josecgomez,

Hate to bother you man, but I’m stumped. I have always used this line of code to pull relevant data from tables outside the scope of the bpm I’m working on, or at least something similar.

Db.OrderRel.Where( r =>r.Company == callContextClient.CurrentCompany && r.OrderNum == 1 && r.OrderLine == 1 && r.OrderRelNum == 1).Select( r =>r.ReqDate.ToString()).DefaultIfEmpty().FirstOrDefault()

In the current Standard Data Directive under SysAgentSched I cannot get that code to populate anything, hence why I’m getting the false statement from earlier. Its defaulting to nothing because it sees nothing. Is there a reason that I cannot access revelant data in a standard data directive?

If this triggers on a taskSchedule the callContextClient is null it won’t have currentCompany in it. (hard code it if you can)
I didn’t read the rest of the thread (sorry burried) but maybe that helps.

1 Like

That was it! Thank you!

1 Like

I usually use Session.CompanyID – callContextClient has burned me too many times (I usually use callContextClient with Service Connect)

3 Likes

Reviving this thread:

New problem, I have begun building out this DD for multiple companies in the same instance and I am not getting the desired results. I have built this Data Directive as Company specific to save on confusion and named them according to the company they were built in. The data directive should fire every time the schedule changes, in this case, every 10 minutes, and send out an email based on the conditioning path laid out for it. I get the email from the original company that I built this for, but I get no emails from the second or third. I have skipped the process of creating a process set and adding something to it and instead decided to simply generate a report on each run of the schedule. I am receiving emails related to the report generation, but not for the data directive running. I believe this may be caused by the fact that I am using a standard directive instead of an in-transaction directive. However, with both of these data directives being in separate companies and being company-specific, I thought they wouldn’t interfere with each other.

Any and all help is greatly appreciated!

It would be much better / easier /less risky to just write a UBAQ put the BPM Code on the GetList Post Processing and schedule that UBAQ Export to run every 10 minutes.

Then you can make a separate BAQ for each… as a matter of fact you are in 10.2.700 you have functions… Just write Scheduled Functions why don’t you just schedule a function to do this for you? Seems a lot safer.

I don’t see a section to run custom c# code in the function designer. Did they replace it with something else?

@josecgomez,

I figured out how to get my c code in there. I would like some help understanding how to call in a table for these functions. I am receiving the following error code when trying to assign a variable:
image
I have created a reference for the table I would like to use, but maybe this isn’t what I’m supposed to use.

Thanks for the help with this!

I’ve figured out how to get the custom code in there. Had to read through the following post and some of the comments to figure out the checkboxes allowed or disallowed code.

I am now getting the following error whenever the function runs. I get that its related to my keys in UD02 but past that I don’t understand how the parameter value could be blank:

This is what my current function looks like. I just want to pull in the only item in UD02. I believe that using the GetById is how I would go about this. I then have an assign statement to grab the value of Ud02.Checkbox01 and assign it to a variable. Lastly, I want an email to go out if the function operates correctly.

Thanks again for helping with this.

Figured out that the error was that I was passing null values into new parameters key1-5. Solved this by assigning values to the variables before the BO call.

New error below. I have no idea where this one stems from, but I assume it has to do with my variables again, or my c# custom code. New function set up, errors, and C# below:

DateTime localDate = DateTime.Now;

LastRun = localDate.ToString();

string myDateString = CaptureDT;
DateTime datetime = DateTime.Parse(myDateString);
string timeString = datetime.ToShortTimeString();
CaptureDTMS = ((int)datetime.TimeOfDay.TotalMilliseconds);
/*+ 3600000;*/

string myDateString2 = LastRun.ToString();
DateTime datetime2 = DateTime.Parse(myDateString2);
LastRun = datetime2.AddHours(-4).ToString();

string timeString2 = datetime2.AddHours(-4).ToShortTimeString();

/*if(timeString2.Contains("AM"))
{
  LastRunMS = ((int)datetime2.TimeOfDay.TotalMilliseconds)-14400000;
}else LastRunMS = ((int)datetime2.TimeOfDay.TotalMilliseconds);
*/
LastRunMS = ((int)datetime2.AddHours(-4).TimeOfDay.TotalMilliseconds);
Difference = LastRunMS - (CaptureDTMS); 



/*if(Difference < 0)
{
  Difference = 5700001;
}*/

@josecgomez
I figured out my issue was with my variables. I was placing them under the Request parameters within the signature instead of just setting them up as variables within the function designer.

New challenge:

I am trying to have this function update table ud02 when certain criteria are met. I would like to use the set field widget in function designer. I also thought that after setting the field to true I would need to call in the update bo method caller. Below is what I have created, but it does not push the updates to the ud02 table.

Any tips or tricks on how to update using these widgets?

Thanks!