Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
1305 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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



Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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?

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 11 23
1090
2
thg 6 24
13271
1
thg 4 24
2090
2
thg 2 24
2478
1
thg 7 23
2239