Update work notes of RITM through API using Request Number

Saquib Mohammed
Mega Guru

I am trying to update the work notes of RITM record using an API. The API will accept the RequestNumber and WorkNotes and update the work notes of RITM record associated with that Request Number. I tried writing the below script in scripted rest api but it doesn't work. Essentially I have 2 questions -

1. Can I query the RITM table using the Request Number in script (not the sys_id but the request number)

2. What would be the script to update the work notes in RITM. using current.work_notes and then gr update don't seem to wirk. Any pointers please - 

var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request'RequestNumber); //I think this doesn't work since it expects the sys_id of the request
grRITM.query();
gs.log('This is GetRowCount:  ' + grRITM.getRowCount());
        while(grRITM.next()){
            current.work_notes = WorkNotes;
            grRITM.update();
        }
2 REPLIES 2

DUGGI
Giga Guru

@Saquib Mohammed 

 

  1. Yes, you can query the RITM table using the Request Number in the script. To do this, you'll need to first query the 'sc_request' table with the Request Number and retrieve the sys_id of the associated request. Then, use this sys_id to query the 'sc_req_item' (RITM) table.
  2. To update the work notes in the RITM, you need to use the "work_notes" field on the GlideRecord object (grRITM) instead of "current.work_notes".

Here's an updated version of your script:

// Replace these placeholders with actual values
var RequestNumber = 'your_request_number_here';
var WorkNotes = 'your_work_notes_here';

// Query the 'sc_request' table to find the sys_id of the request
var grRequest = new GlideRecord('sc_request');
grRequest.addQuery('number', RequestNumber);
grRequest.query();

if (grRequest.next()) {
    var requestId = grRequest.sys_id;

    // Query the 'sc_req_item' table using the sys_id of the request
    var grRITM = new GlideRecord('sc_req_item');
    grRITM.addQuery('request', requestId);
    grRITM.query();

    gs.log('This is GetRowCount: ' + grRITM.getRowCount());

    // Update the work notes in the RITM
    while (grRITM.next()) {
        grRITM.work_notes = WorkNotes;
        grRITM.update();
    }
} else {
    gs.log('Request not found with Request Number: ' + RequestNumber);
}

This script should now work as expected. Make sure to replace the placeholders with the actual Request Number and Work Notes values you want to use.

Slava Savitsky
Giga Sage

Since your GlideRecord object is grRITM, you should use grRITM.work_notes instead of current.work_notes