Business Rules

Phani Pasupulet
Tera Contributor

when an incident is created, then a record should be created in a
problem table and any update in incident record should be updated in
the record created in problem table.(Using Business Rules)

 

I can able to create a problem when incident was created 
but I want the info about how to update the fields of problem record ,if the incident was updated after its creation.
How to map all updated fields

3 REPLIES 3

Riya Verma
Kilo Sage
Kilo Sage

HI There,
Please refer below script which can be used in Script include.

(function executeRule(current, previous) {
    // Check if this is an update and not a new incident
    if (current && previous && current.sys_id === previous.sys_id) {
        var problemGR = new GlideRecord('problem');
        
        // Query the problem record associated with the current incident
        problemGR.addQuery('incident', current.sys_id);
        problemGR.query();
        
        // Check if there is an associated problem record
        if (problemGR.next()) {
            // Update the problem record with the changes from the incident
            if (current.short_description != previous.short_description) {
                problemGR.short_description = current.short_description;
            }
            
            if (current.description != previous.description) {
                problemGR.description = current.description;
            }
            
            // Add more fields to update as needed
            
            // Update the problem record
            problemGR.update();
        }
    }
})(current, previous);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Phani Pasupulet
Tera Contributor

Query the problem record associated with the current incident
problemGR.addQuery('incident', current.sys_id);
problemGR.query();

I didnt under stand the above 


how can we identify the problem record that belongs to this incident record
is there any inter linking field
can you please explain in detail

Phani Pasupulet
Tera Contributor

What is the relation between that incident and problem to query