The CreatorCon Call for Content is officially open! Get started here.

current record is not getting updated using the Workflow Run script.

Yesh
Tera Contributor

Hi Team,

I am trying to update the current record in the workflow run script. When I am trying to use current.update(), workflow giving a warning. So i have removed that line and simple set the value for a field. But the value of the field is not getting update even after the workflow is completed. 

Is there any other way to update the current record in workflow? I have tried using "Set Value" activity also, it is not updating the record.

Any suggestions are helpful.

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Yesh 

Did you try updating the u_status as 4 from background script for that record just for testing?

any before update BR is blocking the update?

try this in workflow run script

current.setWorkflow(false);

current.u_status = '4';

Regards
Ankur

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

View solution in original post

14 REPLIES 14

Sagar Pagar
Tera Patron

Have you tried with Glide Record to update the current record in run script. You can refer below script for the same.

    var currentRecordId = current.getUniqueValue();
	
    var record = new GlideRecord('table_name');
    record.addQuery('sys_id', currentRecordId);
    record.query();
    
	if (record.next()) {
        record.your_field1 = 'values1';
        record.your_field2 = 'values2';
        record.update();
        gs.log('record updated!');
	} else {
        gs.log('record not found');
    }
	

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Yesh
Tera Contributor

Hi @Sagar Pagar ,

Tried like the way you have mentioned. It is not even logging the message.

Thanks

Yesh,

Share your complete script here

On which table workflow is attached?

What should be updated for current record? give example.

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Yesh
Tera Contributor

Hi @Sagar Pagar ,

Workflow is running for the x_import_bulk table. I am updating the status of the current record in that table.

current.u_status = '4';

Status is the choice field. That status should be Error, The value of Error is 4. That is the reason I have mention 4 as a string.

Thanks