跳至内容
菜单
此问题已终结
3 回复
2064 查看

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?

形象
丢弃
最佳答案

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



形象
丢弃
编写者

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.

编写者 最佳答案

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

形象
丢弃

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?

最佳答案

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

形象
丢弃
编写者

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.

相关帖文 回复 查看 活动
3
11月 23
1700
2
6月 24
14061
1
4月 24
3030
2
2月 24
3296
1
7月 23
2933