Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2607 มุมมอง

Hello,

I created a Server Action (Settings->Technical->Actions->Server Actions) and then created a button for this Server Action in the sale.order model. The functionality of the button is to create a Planned Activities when it is confirmed as Backorder. 

I want to call the "action_schedule_activities" function of the "Schedule" button in the  "mail.activity.schedule" model. Since it was added in the "mail.mail_activity_schedule_view_form" form. When I try to implement it, I get the error: 

NameError: name 'self' is not defined

Below is my code in the Server Action:

if records(self):

    action = self.env['mail.activity.schedule'].action_schedule_activities()

I appreciate any answers, thank you!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,In a scheduled action, the self variable, which typically represents the record(s) being processed, will indeed be undefined or empty because scheduled actions are not triggered by a specific record. Therefore, you cannot directly call a function on self in a scheduled action.


To call a function in a scheduled action, you can search for the required records using a suitable model, such as mail.activity.schedule, and then perform the desired operation. Here's how you can do it:


example:

Please try with the below code

if records(self):

    action = self.env['mail.activity.schedule'].self.env['mail.activity.schedule'].search([], limit=1)

        if action:

            record_to_process = action[0]

             record_to_process.action_schedule_activities()


Hope it helps


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ม.ค. 23
2850
1
ธ.ค. 24
3966
0
พ.ย. 24
1625
2
ส.ค. 24
1428
2
ก.ค. 24
3335