How to associate SCTASK/Incident records with Projects in SPM without using parent field?

ATRIVEDI
Tera Contributor

We want to configure our Assignment Rules and SLAs based on the Project. Although we have a Project variable available on the frontend catalog form, we are unable to identify any dedicated field at the SCTASK/Incident level where this Project information can be stored and used for backend logic.

Points to note:

  1. We do not want to rely on variables using “Show Related Fields,” as using variables directly for such logic is not future-proof.

  2. While the Parent field is available, it is already used for multiple relationships such as ENHNC, REQ, etc. Currently, SCTASK records are linked with RITMs through the Parent field, and in future, if Enhancement and SCTASK relationships are introduced, this approach may create conflicts and ambiguity.

2 REPLIES 2

GlideFather
Tera Patron

ahoy @ATRIVEDI,

 

there are quite plenty options here. But what I would try as the first option is to map the variable called Project to a Parent field.

 

Which means if you submit that catalog item, the value from the Project variable will be added to the Parent field. Ensure that the variable and target field are of the same type (e.g. reference using sys ID on the same table).

 

GlideFather_0-1779270478789.png

 

Either on the variable definition go with Map to field: true & Map the field like this:

GlideFather_1-1779270989245.png

 

Or in the script field (depends on the table of your catalog item x record producer):

current.backend_field = producer.variable_name;

 

_____
Answers generated by GlideFather. Check for accuracy.

Tanushree Maiti
Tera Patron

Hi @ATRIVEDI 

 

If you do not "want to rely on variables using “Show Related Fields"

In that case, 

open the Incident and sc_task tables.

  • Create a new field with the following properties:
    • Type: Reference
    • Reference: Project [pm_project]
    • Column Label: Project (like u_project)
  • Create an After-Insert Business Rule on sc_req_item.

     Condition: current.variables.project_variable_name != '' (Replace with your actual variable name).

 

         Sample code/update as per your requirement:

 

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

    var sctask = new GlideRecord('sc_task');

    sctask.addQuery('request_item', current.sys_id);

    sctask.query();

    while (sctask.next()) {

        sctask.u_project = current.variables.project_variable_name; // Set your custom field

        sctask.update();

    }

})(current, previous);

 

  •  In Service Level Management > SLAs > SLA Definitions, set the start condition to evaluate Project  . 

 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti