Capturing Key Risks field values into a single Project field

rdskn023ET
Tera Contributor

Has anyone ever, or is it possible, to create a field at the project level and program it to capture the project's key risks under the risks table into a single field? For instance, if Project A has three risks associated with it and two of them are marked as key risks, I would like to capture at least the short description of each of them and have it populated into that project field. If I could capture more information of the key risks items, i.e. number, etc., that would be great, but mainly I need to see if there is a way to capture any values from a different table and populate them into a new field. If anyone has any examples or could offer any insight on how to accomplish it, it would be greatly appreciated. Thanks!

2 REPLIES 2

Jyoti_D_kamthe1
Tera Contributor

Hi @rdskn023ET  ,

Create a new field on the Project table:

Go to the Project table in the ServiceNow application.

Create a new field to store the key risks information. This field could be a text field or a reference field, depending on your needs.

Identify key risks:

On the Risks table, you might have a field to mark risks as "key risks." Ensure you have a way to identify these key risks.

Create a Business Rule:

Create a Business Rule that triggers when a risk record is updated or when a key risk is identified.

In the Business Rule script, query for the key risks associated with the specific project and concatenate the relevant information into a string.

Update the newly created field on the Project table with this string.

Example Business Rule script (using GlideRecord):

 

(function executeRule(current, previous /* previous is null for inserts */) {
    // Check if the risk is marked as a key risk
    if (current.key_risk == true) {
        // Query the Project record associated with this risk
        var projectGR = new GlideRecord('project');
        if (projectGR.get('sys_id', current.project.sys_id)) {
            // Update the key_risks_field with relevant information
            projectGR.setValue('key_risks_field', projectGR.getValue('key_risks_field') + '\n' + current.short_description);
            projectGR.update();
        }
    }
})(current, previous);

 

Depending on your specific requirements, you might need to adjust the script or even consider additional features like UI Policies or Client Scripts to enhance the user experience.

Thanks,

Jyoti Kamthe

Thanks Jyoti. 

 

This is the path I was going down and I have made a few modifications to my code based on yours and I still am unable to get any of the risk data into the project field. I have tried your code after matching up the field names and project table name, but still to no avail. 

 

I will keep attempting other modifications and ways to see if this can be done. If there are any other ideas, please let me know. Thanks!