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.

Business rule error for updating comments as additional comments

Gopal14
Tera Contributor

Hi,

 

Below is my BR

 

var additionalComments = current.comments.getJournalEntry(-1);  
    var caseGR = new GlideRecord('sn_customerservice_case');
    caseGR.addQuery('sys_id', current.case);
    caseGR.query();
    if (caseGR.next()) {
        // Add comments to the related case
        caseGR.comments = 'Additional comments from incident: ' + additionalComments;
        caseGR.update();
    }
 
Gopal14_0-1717053163849.png

 

Can you please help

7 REPLIES 7

dgarad
Giga Sage

Hi @Gopal14 

try the below code

var additionalComments = current.comments.getJournalEntry(-1);  
    var caseGR = new GlideRecord('sn_customerservice_case');
    caseGR.addQuery('sys_id', current.sys_id);
    caseGR.query();
    if (caseGR.next()) {
        // Add comments to the related case
        caseGR.comments = 'Additional comments from incident: ' + additionalComments;
        caseGR.update();
    }
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Gopal14
Tera Contributor

comments are still not updating as a Additional Comments

 

Mark Manders
Mega Patron

Assuming you want the latest comments to sync (not sure what '-1' returns):

var comments = current.comments.getJournalEntry(1);
var caseRec = new GlideRecord('sn_customerservice_case');
caseRec.addQuery('sys_id',current.case.getValue()); // assuming case is the correct field on the incident table
caseRec.query();
if(caseRec.next()){
caseRec.comments = 'Additional comments from Incident ' + comments;
caseRec.update();
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders ,

 

 

Receiving below error

 

Gopal14_0-1717054645797.png