Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
256 Näkymät

I'm using the 18.3 version, and I have a CRM pipeline that I would like to automate to create a new task in a specific project once an opportunity reaches a specific stage. I know how to set the trigger in the automation, but I don't know how to write a code to execute.


Thank you,

Randy

Avatar
Hylkää
Paras vastaus

First, let's make it clear - there is an automatic way of creating task in Project, when Sales Order is confirmed, so make sure it is not what you need.

If you want to create a Task in specific Project, only if the specific Stage is reached, this is the automation code you want:

project = env['project.project'].search([('name', '=', 'MyProject')], limit=1)

if project:
    new_task = env['project.task'].create({
        'name': 'Task Name',
        'project_id': project.id,
        # Add other fields here
    })
else:
    raise UserError("Project could not be found!")

With this code, on trigger you search for "MyProject" project. If it is found, new task "Task Name" is created in it. If it is not found user gets Error.

Adjust the code to your needs!

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
syysk. 25
2077
2
huhtik. 25
2698
1
maalisk. 25
2211
1
maalisk. 25
2304
1
helmik. 25
4065