تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
1499 أدوات العرض

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
نوفمبر 23
1229
2
يونيو 24
13435
1
أبريل 24
2315
2
فبراير 24
2653
1
يوليو 23
2424