Before BR with Update

karthik65
Tera Guru
Hi ,
 
I want to remove update from this BR. Is there a way to remove update from the Script and Glide Api.
 
    updateChildren('comments', gs.getMessage('Comment copied from RITM'));
 
 
 
function updateChildren(fieldName, msg) {
    var rec = new GlideRecord("sc_task");
    rec.addQuery('request_item', current.sys_id);
    //rec.addActiveQuery();
    rec.orderBy();
    rec.query();
 
    var fieldRawValue = current.getValue(fieldName) + '';
    var fieldValue = fieldRawValue.trim();
    if (!fieldValue || fieldValue.length <= 0)
        return;
 
    while (rec.next()) {
 
        if (fieldRawValue.indexOf('Comment copied from') == 0)
            rec[fieldName] = fieldRawValue;
        else
            rec[fieldName] = msg + ': \n' + fieldRawValue;
if(rec.state == '-5' && (rec.request_item.request.requested_for == gs.getUserID() || rec.request_item.request.opened_by == gs.getUserID())){
rec.setValue('state', '2');
}
        rec.update();
 
    }
 
}
7 REPLIES 7

Danish Bhairag2
Tera Sage
Tera Sage

Hi @karthik65 ,

 

You can try something like this in ur code

 

rec.setWorkflow(false);
rec.update();
rec.setWorkflow(true);

 

Source: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715782

 

Thanks,

Danish

 

karthik65
Tera Guru

@Danish Bhairag2  I have Scripts running after this BR. so we cannot use Setworkflow in this scenerio

Hi @karthik65 ,

 

I agree with Ankur here. As u r trying to update the record in another table you do require .update() here.

 

Thanks,

Danish

 

Ankur Bawiskar
Tera Patron
Tera Patron

@karthik65 

what are you actually doing in this BR? what's your business requirement?

It looks BR is on RITM table and you are updating catalog task, then why not to use update()?

Without update() record won't get updated

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