Skip to Content
Menu
This question has been flagged
1 Reply
2035 Views

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!

Avatar
Discard
Best Answer

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


Avatar
Discard
Related Posts Replies Views Activity
2
Jan 23
2440
1
Dec 24
2399
0
Nov 24
898
2
Aug 24
860
2
Jul 24
2033