Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

update the description of the new record with existing

purnendutiw
Tera Contributor

How can we solve this.. I am getting  so much confusion on this.

 

When a record is created from another record, update the description of the new record with existing description + this record has been created with the Incident number.

 

 

1 ACCEPTED SOLUTION

@purnendutiw 

update as this

(function executeRule(current, previous /*null when async*/) {
var newRecord = new GlideRecord('incident');
newRecord.initialize();
newRecord.description = current.description;
newRecord.short_description = 'this record has been created with the ' + current.number;
newRecord.insert();
}
)(current, previous);

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@purnendutiw 

what's your confusion?

what script did you start with and where are you stuck?

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

   (function executeRule(current, previous /*null when async*/) {
        var newRecord = new GlideRecord('incident');
        newRecord.initialize();
        newRecord.description = current.description;
        newRecord.short_description = current.short_description('this record has been created with the ' + current.number);
        newRecord.insert();
    }
 )(current, previous);
When to run : After, Insert


@purnendutiw 

update as this

(function executeRule(current, previous /*null when async*/) {
var newRecord = new GlideRecord('incident');
newRecord.initialize();
newRecord.description = current.description;
newRecord.short_description = 'this record has been created with the ' + current.number;
newRecord.insert();
}
)(current, previous);

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

vishwajeet5550
Mega Guru

 

 

Create a New Business Rule:

Name: "Update Description with Incident Number"

Table: Choose the relevant table where the record is being created 

When: After Insert

Condition: Check if the record was created from an Incident (you can check if there’s a Parent or Incident field on the table).

(function executeRule(current, previous /*null when async*/) {
    if (current.incident) {
        var incidentNumber = current.incident.number; 
        var descriptionText = current.description || '';
        current.description = descriptionText + "\nThis record has been created with the Incident number: " + incidentNumber;
        current.update();
    }
})(current, previous);