New Incident_Task not associating with the Incident it was created from.

Scott29
Kilo Sage

When I am on the Incident form, go down to the "incident_tasks" related lists, and click the new button.

 

Scott29_0-1741880404048.png

 

It creates a new task, but it doesn't create the relationship between the task and the incident. What do I need to do to make that relationship automatic? 

 

Scott29_1-1741880458141.png

 

 

1 ACCEPTED SOLUTION

KKM
Tera Guru

t looks like when you click "New" under the Incident Tasks related list, a new task is created, but the Incident field is not automatically populated. To fix this and establish the relationship automatically, follow these steps:

Solution: Use a Business Rule or Client Script

Option 1: Business Rule (Recommended)

  1. Navigate to System Definition > Business Rules.

  2. Click New.

  3. Configure the rule as follows:

    • Name: Auto-populate Incident Field
    • Table: Task (or incident_task if applicable)
    • Advanced:  (Check the Advanced box)
  4. In the When to run section:

    • When: Before
    • Insert:  (Check this option)
  5. In the Script tab, add the following script:

     
    if (!current.incident && current.parent) { current.incident = current.parent; }
  6. Click Save or Submit.

Option 2: Client Script (For Immediate UI Update)

  1. Navigate to System Definition > Client Scripts.

  2. Click New.

  3. Configure the script:

    • Name: Auto-fill Incident Field
    • Table: incident_task
    • Type: onLoad
  4. Add this script:

     
    (function executeRule(current, gForm, gSNC) { var incidentSysId = gForm.getParameter('sysparm_parent'); if (incidentSysId) { gForm.setValue('incident', incidentSysId); } })(current, gForm, gSNC);
  5. Click Save.

Hope this works for you.

  • The Business Rule ensures the task is linked before it is inserted into the database.
  • The Client Script updates the UI immediately when a new task form is opened.

Kindly mark it as "Accepted Solution"/"helpful", as it resolves your query. Please press like button for the resolution provided.

With Regards,
Krishna Kumar M - Talk with AIT3ch
LinkedIn: https://www.linkedin.com/in/mkrishnak4/
YouTube: https://www.youtube.com/@KrishAIT3CH
Topmate: https://topmate.io/mkrishnak4 [ Connect for 1-1 Session]

View solution in original post

2 REPLIES 2

KKM
Tera Guru

t looks like when you click "New" under the Incident Tasks related list, a new task is created, but the Incident field is not automatically populated. To fix this and establish the relationship automatically, follow these steps:

Solution: Use a Business Rule or Client Script

Option 1: Business Rule (Recommended)

  1. Navigate to System Definition > Business Rules.

  2. Click New.

  3. Configure the rule as follows:

    • Name: Auto-populate Incident Field
    • Table: Task (or incident_task if applicable)
    • Advanced:  (Check the Advanced box)
  4. In the When to run section:

    • When: Before
    • Insert:  (Check this option)
  5. In the Script tab, add the following script:

     
    if (!current.incident && current.parent) { current.incident = current.parent; }
  6. Click Save or Submit.

Option 2: Client Script (For Immediate UI Update)

  1. Navigate to System Definition > Client Scripts.

  2. Click New.

  3. Configure the script:

    • Name: Auto-fill Incident Field
    • Table: incident_task
    • Type: onLoad
  4. Add this script:

     
    (function executeRule(current, gForm, gSNC) { var incidentSysId = gForm.getParameter('sysparm_parent'); if (incidentSysId) { gForm.setValue('incident', incidentSysId); } })(current, gForm, gSNC);
  5. Click Save.

Hope this works for you.

  • The Business Rule ensures the task is linked before it is inserted into the database.
  • The Client Script updates the UI immediately when a new task form is opened.

Kindly mark it as "Accepted Solution"/"helpful", as it resolves your query. Please press like button for the resolution provided.

With Regards,
Krishna Kumar M - Talk with AIT3ch
LinkedIn: https://www.linkedin.com/in/mkrishnak4/
YouTube: https://www.youtube.com/@KrishAIT3CH
Topmate: https://topmate.io/mkrishnak4 [ Connect for 1-1 Session]

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Scott29 

It should display the incident number. If it doesn't, you need to add the logic to the new button, where it should map these two fields.

 

https://www.servicenow.com/community/itsm-forum/how-to-auto-populate-incident-field-in-incident-task...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************