Need to add a condition in workflow

Snow-Man
Tera Contributor

Hello everyone, 

 

I have a requirement to write a if condition in workflow to validate

1. if Kb article is new then trigger one event

2. if it is already existing article meaning it is 2nd etc versions, I need to trigger another event.

 

how can I achieve this? I am super new to workflows! 

thanks,

snowman

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Snow-Man You can use Run Script workflow activity in your workflow for this purpose https://docs.servicenow.com/bundle/xanadu-servicenow-platform/page/administer/workflow-activities/re... and use following script in it.

 

var kbArticle = current;
if (kbArticle.version == 1) {
    // If the KB article is new (first version)
    gs.eventQueue('event.new.kb.article', kbArticle, kbArticle.sys_id, gs.getUserID());
} else if (kbArticle.version > 1) {
    // If the KB article is an updated version
    gs.eventQueue('event.updated.kb.article', kbArticle, kbArticle.sys_id, gs.getUserID());
}

 

Hope this helps.

Hi Sandeep, I just wrote to trigger event as an example. 

MY requirement is to trigger one more script if the version is new and skip if there are more versions. 

so can I use same script in if condition to achieve that?

@Snow-Man Yes you can.