Skip to Content
Menu
This question has been flagged
3 Replies
1259 Views

Is it possible to add simple logic to a custom field in studio?


I have two date fields:

One for the planned delivery date

One for actual delivery date


This is tracking late orders so the actual will always be later than planned.


I then want a "days late" field that autmatically subtracts the two dates in the fields above and displays the days late.


Is this possible in Studio please?

Avatar
Discard
Best Answer

It is possible in Studio with a computed field.

After adding the field, click on MORE at the bottom (or find the field from the Fields menu option and add some simple Python code to calculate the days late, something like this:


 

[EDIT] The correct code is something like this (to trap errors):

 if record.x_studio_actual_delivered_date and record.x_studio_original_delivery_date:

     record['x_studio_days_late_integer'] = (record.x_studio_actual_delivered_date - record.x_studio_original_delivery_date).days

  else:

    record['x_studio_days_late_integer'] = 0



Avatar
Discard
Author

Brilliant thank you. I have had a go at this but unfortunately I am missing something as it's throwing an error ...
I can t even work out how to post an image here!

My three fields are:
x_studio_original_delivery_date
x_studio_actual_delivered_date
x_studio_days_late_integar

my dependencies are listed as:
x_studio_original_delivery_date, x_studio_actual_delivered_date

compute is:
for record in self: record['x_studio_days_late_integar'] = record.x_studio_original_delivery_date - record.x_studio_actual_delivered_date

Appreciate any further help with this

I'm not a Python programmer, and debugging Python code is one of my least favourite things to do! It's easy to have something slightly wrong and you can get an error.

You can't post images in answers, but you should be able to post links to an image hosted elsewhere. It's the last few lines of the error that provide the details.

Author Best Answer

Thank you Chris for your help. I got into trouble as the error was stopping me getting back in to Studio to correct it. Had to pass it through our Gold partner.

It turns out that I had forgotten to error trap if either of the date field was not completed:

for record in self:

  if record.x_studio_actual_delivered_date and record.x_studio_original_delivery_date:

     record['x_studio_days_late_integar'] = (record.x_studio_actual_delivered_date - record.x_studio_original_delivery_date).days

  else:

    record['x_studio_days_late_integar'] = 0

Avatar
Discard

Yes, that makes sense. I'll update my answer to include this. Maybe someone can mark this as correct so other people can find it?

Best Answer

Hello, you can not do it in the Studio mode. 

You can only do it in the developer mode:

- go on the object view you would like to see

- click on the developer icon, then create a new field

- in order to add the logic you have to fill in the logic you want to enable in the field 'Compute'


I hope it was helpful

Avatar
Discard
Author

Thank you very helpfull. Back to our Gold partner and another big bill it is then!

I added another answer explaining how to define a computed field.

Related Posts Replies Views Activity
3
Nov 23
1082
2
Jun 24
13208
1
Apr 24
2078
2
Feb 24
2463
1
Jul 23
2227