Create a custom Flow action to Update Record with Workflow(false)

daisybora
Tera Contributor

I am trying to create a custom flow action for Update Record with setWorkflow(false).

Similar to the OOB action, I have added three inputs:

Table (type Table Name)

Record (type Document ID, dependent on Table)

Fields (type Template Value, dependent on Table)

I am using a custom script step with the following code, where setWorkflow(false) does not seem to work. Does anyone have any suggestions please. 

 

Note: The input.fields is in this format: 

'install_status=1^stockroom={"display":"StockNameDisplayName","value":"1d62222bdb9c08d0d9268e3505961970","sys_id":"1d62222bdb9c08d0d9268e3505961970"}'
 
Script Step:
var gr = new GlideRecord(inputs.table);
gr.addEncodedQuery('sys_id=' + inputs.record.sys_id);
gr.setLimit(1);
gr.query();
if(gr.next()){
        gr.applyEncodedQuery(inputs.fields);
        gr.setWorkflow(false);
        gr.update();
}
5 REPLIES 5

Zach Koch
Giga Sage
Giga Sage

You need to capitalize the word flow in the function call, so it should be gr.setWorkFlow(false), you have gr.setWorkflow(false)

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Thanks Zach for your response, but it does not work.

Also, the correct syntax is gr.setWorkflow() [without the upper case].

Thank you!

Kristy Merriam
Administrator
Administrator

Hi @daisybora,

 

I think there are two things at play here:

 

1. Move the setWorkflow(false) before your query statement

2. You values in applyEncodedQuery should look like this instead: 

'install_status=1^stockroom=2eaa2b3f3763100044e0bfc8bcbe5de2'
 
You're sending the JSON object for stockroom and I think that's why it is not getting set.
 
Example:
var grAsset = new GlideRecord('alm_asset');
grAsset.addEncodedQuery('sys_id=' + '17c1fa8837f3100044e0bfc8bcbe5d61');
grAsset.setLimit(1);
grAsset.setWorkflow(false);
grAsset.query();
if (grAsset.next()) {
    grAsset.applyEncodedQuery('install_status=1^stockroom=2eaa2b3f3763100044e0bfc8bcbe5de2');
    grAsset.update();
}

gs.info(grAsset.stockroom.getDisplayValue());



Ankur Bawiskar
Tera Patron
Tera Patron

@daisybora 

I verified setWorkflow(false) does work with applyEncodedQuery()

try with this input

install_status=1^stockroom=1d62222bdb9c08d0d9268e3505961970

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