adds the additional comment twice

Community Alums
Not applicable

Hi, I have written a server script in a ServiceNow widget. When this code executes, it adds the additional comment twice. I want it to create the comment only once

 

here is my code

 
if (input.app) {
    // gs.addErrorMessage("my comments "+input.app);
	  // gs.addInfoMessage("my my approval record "+input.Record_sys_id);
	  var approvalSysId = input.Record_sys_id;

  var grApproval = new GlideRecord('sysapproval_approver');
  if (grApproval.get(approvalSysId)) {
		  grApproval.state='rollback';
		  grApproval.update();
    var taskSysId = grApproval.sysapproval;
    if (taskSysId) {
      var table_name=taskSysId.getRefRecord().getTableName();
       var grBR = new GlideRecord('sys_journal_field')
			        grBR.setWorkflow(false);
							grBR.query();
							grBR.initialize();
							grBR.name =table_name ;
							grBR.element = 'comments';
							grBR.element_id =taskSysId;
							grBR.value = input.app;
							grBR.insert();
    }
  }
  } 
5 REPLIES 5

J Siva
Tera Sage

Hi @Community Alums 
Is there a specific reason to add comments by inserting them into the sys_journal_field table instead of updating the comments directly in the task table using the taskSysId?

Regards,
Siva

Community Alums
Not applicable

@J Siva 

this also  adding comment twice

if (input.app) {
    // gs.addErrorMessage("server script"+input.app);
	  // gs.addInfoMessage("testing everything"+input.app+" --"+input.Record_sys_id);
	  var approvalSysId = input.Record_sys_id;

  var grApproval = new GlideRecord('sysapproval_approver');
  if (grApproval.get(approvalSysId)) {
		  grApproval.state='rollback';
		  grApproval.update();
    var taskSysId = grApproval.sysapproval;
    if (taskSysId) {
      var taskGR = new GlideRecord(taskSysId.getRefRecord().getTableName());
      if (taskGR.get(taskSysId)) {
        taskGR.comments = input.app;
				 taskGR.setWorkflow(false);
        taskGR.update();
      }
			
    }
  }
    
  } 

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

what's your actual business requirement? please explain that with screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Community Alums
Not applicable

Hi @Ankur Bawiskar , i have created widget and which have the approve reject and "more info required" button when i click on the more info required button i show one popup window to enter the additional comment. and when i submit that additional comment should reflects on that record's additional comment