Create Project Risk based on criteria in scheduled job

mborkowski
Tera Contributor

Good Morning all--thanks in advance for your help!
Have a request to create a Project Risk on associated project based on certain criteria
Sorry fairly new to scripting so be patient..

 

create a Project Risk on associated project:

All 3 of these conditions:

Project type (project_type) = Deployment

Project State (state) = Open or Work in Progress

Expected CAR Date u_expected_car_date has passed

 

I need to create a scheduled job but also want to include a script that would auto create the project risk

can this be done all in same script include?

 

Any help is greatly appreciated (I have attached a data mapping for the risk record fields needed & what is default field values)

here is my script that I have-I need to run the job nightly

// script for checking overdue Expected CAR date and creating risks
    var grpm_project = new GlideRecord('project');

    grproject.addQuery('u_expected_car_date', '<', gs.nowDateTime()); // Find projects with expected due dates in the past
    grproject.addQuery('state', '=', 2 or 10  ); // state of Open or Work in Progress)
    grproject.addQuery(‘project_type’, ) '=',  Deployment

 

grproject.query();


    while (grproject.next()) {
        var grRisk = new GlideRecord('risk'); // Create a new risk record
        grRisk.initialize();
        riskGR.setValue('short_description', Risk created due to incorrect CAR Data);// Risk Name
        riskGR.setValue('description',’ CAR related risk created because the field contains incorrectly filled out CAR data');

riskGR.setValue,(state;'open');

riskGR.setValue('probability', medium);

riskGR.setValue('impact', medium);

riskGR.setValue('u_response_type; ’ Mitigate.');

riskGR.setValue('u_category_type’, Finance);

riskGR.setValue(‘u_risk_sub_category’, Car Availability);

riskGR.setValue(‘mitigation’, ‘Confirm receipt of CAR and unblock purchase related or CAR-related tasks’);

 

riskGR.setValue(‘assigned_to’, Project Program Manager listed under u_program_manager on project record

 

riskGR.setValue(‘risk_owner.name’, user that’s in project_manager field on project record

 

riskGR.setValue('due_date’, expected car date + 14 days (how can I accomplish this?

riskGR.setValue('u_impact_date’, expected car date + 7 days (how can I accomplish this?

 

riskGR.setValue('project name’, Project Name: ${task.short_description} how do I grab this // Replace with the actual name of project

riskGR.setValue('task’, how do I grab this); // Replace with the actual sys_id of the project

      


        grRisk.insert();
    }

 

2 REPLIES 2

Swapna Abburi
Mega Sage
Mega Sage

Hi @mborkowski 

For this, you can use low-code solution using Flow designer. Are you looking to create Project risk whenever the given conditions met or periodically as a schedule?

 

Both are possible with Flow designer. For former requirement, you can use Flow designer with updated trigger whereas for the later one, you can use trigger type as schedule.

I need a nightly job created to check if the car date has passed then create script

I have edited to include script