Could not update worknote in RITM

Ravivarman Saee
Tera Contributor

i am running below script to update ritm work note, but it is not updating if i set workflow to false. why? if i don't set it to false then it updates RITM work note. I don't see any other Business rules impacting this


var at = new GlideRecord('sc_req_item');
at.addEncodedQuery('cat_item=20ace1b01b8fa9d04278dbd1f54bcb90^stateNOT IN3,4^variables.a91d29781b8fa9d04278dbd1f54bcbb8=Read-only Access^number=RITM2424724');
at.query();

while (at.next()) {
at.work_notes = 'Cancelling 5';
at.setWorkflow(false);
at.autoSysFields(false);
at.update();
}
gs.info('Updated ' + at.getRowCount() + ' RITMs.');

4 REPLIES 4

Mark Manders
Mega Patron

Try it like below. Work notes are copied to the activity stream, so you are running other logic. Your script does update the worknotes, but the 'at.update()', updates the record and you expect the notes in the activity stream (after update the work notes field gets emptied). Because the setWorkflow(false) doesn't allow anything else to run, your work notes aren't logged into the activity stream (sys_journal_field table).

var at = new GlideRecord('sc_req_item');
at.addEncodedQuery('cat_item=20ace1b01b8fa9d04278dbd1f54bcb90^stateNOT IN3,4^variables.a91d29781b8fa9d04278dbd1f54bcbb8=Read-only Access^number=RITM2424724');
at.query();

while (at.next()) {
    // Update work_notes separately
    var workNotesUpdate = new GlideRecord('sc_req_item');
    if (workNotesUpdate.get(at.sys_id)) {
        workNotesUpdate.work_notes = 'Cancelling 5';
        workNotesUpdate.update();
    }

    // Perform other updates with workflow disabled
    at.setWorkflow(false);
    at.autoSysFields(false);
    at.update();
}

gs.info('Updated ' + at.getRowCount() + ' RITMs.');

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

Ravivarman Saee
Tera Contributor

it worked thank u.

Ravivarman Saee
Tera Contributor

But what is the purpose of setting workflow to false below then since we already updated the RITM worknote. 
what i need to do is, when i update the worknote, i dont want any other Business rule or script to run. Thats why i set it to false. In this case after updating, if i set it to false, won't there be any other business rules running ?

Mark Manders
Mega Patron

You are still setting it to false, so no other rules are running, but you need the update of the worknotes to run (and worknotes aren't fields on your form, they are records from another table, and that insert in that other table needs to run.
You can validate it by creating a simple BR to do something after update and check if it's running or not after running your script (it won't).


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