Script help ! : A record should not be closed if it does not have a tag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 01:18 PM
We have a requirement:
A user should not be able to move a record to close state if there is no tag associated to it on sn_si_task table.
I have written code but not working:
BR before for when state changes to closed complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 01:28 PM
Assuming your closed state is 3 and other state or previous state is 2.
Please change following line you code to this:
if (current.state == closedState && current.state.changes() && previous.state == otherState)
This condition will be applied when even record changes its state from 2 to 3 and then checks if tags are nil.
as per your script this is the only scenario when you want it show error message so corrected above line.
Try ,test it, if you still see any issue , please share the screenshot and use case you are trying with
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 05:42 PM
Sushant ,
Thanks for the response,
I have made the code change and still able to close the record without a tag.
use case: User has to have a tag associated with the record before moving it to closed state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 08:12 PM
Hi @Servicenow lear ,
As far as I see you want to prevent record from moving to Closed state when there is no Tags associated with it.
Then why do you need this line of code: if (current.state == closedState && current.state.changes() && previous.state == otherState)?
Just make an BR on before - Update - with condition:
[State changes from New to Closed]
AND
[Tags is Empty]
Actions tab:
[Abort action] ticked.
[Add message] ticked -> Input the message content.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 08:41 PM
Tags does not provide that option in query builder