콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2672 화면

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


아바타
취소
관련 게시물 답글 화면 활동
2
1월 23
2892
1
12월 24
4078
0
11월 24
1669
2
8월 24
1451
2
7월 24
3409