Directive to populate UD field based on criteria

Hi all,

We have created a UD date field within JobHead which we are looking to use an in-transaction data directive to populate the field with todays date minus the production prep buffer days stored against the Part

I’ve created a Set Field rule, and can see there is a ‘AddInterval()’ function, but struggling to see how I’d then bring in the Part.ProductionPrepBuffer to this expression when the only available data within this directive is from ttJobHead, as expected.

I was wondering if anyone has achieved something similar when looking at two different tables to use within the same expression, or if I need to be looking at the Set by Query option instead?

Thanks alot in advance!! :smiley:

You won’t be able to populate a field from a different table through Set Field widget.

Set by Query would also won’t work in your case.

I remember doing something similar earlier, Update Table by Query should get you started.
Assign relation between this two table.

Display following fields:

Under configured settings:
Hit on Bind Automatically and you will see Company,Plant,PartNum binded to Part Plant fields:

Also, I don’t have any field to test this but on your custom field where you want to populate, add the expression as:
image

Feel free to post any screenshot if you get stuck!

2 Likes

Wow!! :star2: Honestly thank you SO much for this and all the detailed steps too!! Really appreciate it!!! :smile:

I’ve set up the Update Table section, and is it now I need to bring in a Set Field to enter the expression please?

This expression should update your custom field at ttJobHead upon save. Why do you need Set Field widget?

Can you show your configured settings?

1 Like

Ahh sorry, I’m not sure where to enter the expression. So thought maybe I’d need to bring in a Set Field widget. Would it be using Execute Custom Code instead please?

You should be able to add it here:

BpmFunc.AddInterval(BpmFunc.Today(),TimeSpan.FromDays(-queryRow.PartPlant_PrepTime))

Once expression is added, just hit ok, save the BPM, enable it and test it out.

1 Like

Sorry!! Please ignore me ha! I’m in the browser and couldn’t see the drop-down arrow! :sweat_smile:

1 Like

Thank you so much! This has been really helpful :smile:

I think there’s an issue with it not liking PrepTime being an integer trying to subtract from a Date field :thinking:

Wasn’t this the requirement?

It certainly was! Thank you for help in getting me to this point. I believe the issue lies with what we are trying to achieve, we will need to reassess due to the data type mismatch.

1 Like

Just thought to share the code/expression we have to work around the DateTime/Int error if it helps anyone trying to do something similar :slight_smile:

DateTime.Today.AddDays(-queryRow.PartPlant_PrepTime)

Turns out the criteria has changed and we now need to figure out how to replace Today with JobHead.PlannedKitDate within this expression, so it reads Planned Kit Date-PrepTime so still a bit of a work in progress.

BpmFunc.AddInterval(ttJobHeadRow.PlannedKitDate,TimeSpan.FromDays(-queryRow.PartPlant_PrepTime))

This should help !?

1 Like

This worked perfectly!! Thank you SO much!! :smile: :confetti_ball:

Just out of interest, if its possible please, do you know how we could bring in a WeekDay() function to this expression so that it excludes weekends when doing the calculation?