The 'Short Description' field from the release parent is not populating the 'Project Name' field

CarolMa6
Tera Expert

Hi, 

 

I'm trying to configure the 'Short Description' field from the release parent to populate the 'Project Name' field in related tasks. However, the current business rule is incorrectly updating the related tasks using the 'Description' field from the related phase task instead of the release parent.

 

table: rm_task

when: display

script: 

(function executeRule(current, previous /*null when async*/ ) {

    current.u_project_name = current.parent.short_description;

})(current, previous);

 

Regards 

CarolMa

 

 

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@CarolMa6 

your business rule should work if

1) you are clicking New button in related list of rm_task

2) if the parent has short_description populated

If you are not using New button for testing then make your BR as Before Insert and Not Display

Even after that it will work only when Parent is having short description

what debugging did you do? share some screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Shashank_Jain
Kilo Sage

@CarolMa6 ,

Try the below updated script.

Use a Before Insert/Update BR + replace direct reference with getRefRecord() + check isValidRecord().

(function executeRule(current, previous /*null when async*/) {

    if (current.parent) {
        var parentGr = current.parent.getRefRecord();  // safely fetch parent
        if (parentGr.isValidRecord()) {
            current.u_project_name = parentGr.short_description; 
    }

})(current, previous);

 

Hope it helps!

 

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

Bhuvan
Kilo Patron

@CarolMa6 

 

I believe you are trying to create a related planned task 'pm_project' when 'rm_task' record is inserted.

 

Please see below for business rule and sample record for testing. I have created before BR on insert condition and you can add filter conditions [for example, check rm_task parent field is not empty] as per your requirements.

(function executeRule(current, previous /*null when async*/) {
// Add your code here
var grProject = new GlideRecord('pm_project');
grProject.initialize();
grProject.short_description = current.parent.short_description; 
grProject.parent = current.sys_id;
grProject.insert();
})(current, previous);

Bhuvan_1-1756731675672.png

Bhuvan_0-1756731651977.png

Please note, as part of testing I have disabled 'Update Total Plan Cost In Proj Currency' BR in my PDI as it checks additional information before inserting a record in pm_project table. You can extend the logic accordingly.

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

@Bhuvan  @Shashank_Jain @Ankur Bawiskar 

 

Release record (Parent) label Project name, name: ‘short_description’

CarolMa6_0-1756732185129.png

 

 

Release phase record label: Project name and name: ‘short_description’

CarolMa6_1-1756732185131.png

 

 

Related release task record, project name taken from the project phase

CarolMa6_2-1756732185133.png

 

 

 

Table: rm_task

When: before

When to run insert and update

Script:

(function executeRule(current, previous /*null when async*/ ) {

 

    if (current.parent) {

        var parentGr = current.parent.getRefRecord(); // safely fetch parent

        if (parentGr.isValidRecord()) {

            current.u_project_name = parentGr.short_description;

            gs.log("Release Task BR: Project name set to '" + current.u_project_name + "'");

        } else {

            gs.log("Release Task BR: Parent record is invalid.");

        }

    } else {

        gs.log("Release Task BR: No parent Release associated with this Release Task.");

    }

 

})(current, previous);

 

dont why its populating the release phase task short description and not the release(parent) record 

 

Regards 

CarolMa