Need to add a condition in workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 01:15 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 01:28 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 01:32 AM - edited 09-13-2024 01:33 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 01:49 AM
@Snow-Man Yes you can.