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

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!

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

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


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 23
2854
1
thg 12 24
4001
0
thg 11 24
1634
2
thg 8 24
1439
2
thg 7 24
3355