How can I check to see if a string is >= a number (Knowledge Version)?

Casey23
Tera Guru

Hello,


I am working on a UI action for KB articles. The goal of the UI action is to allow an author to be able to publish their own articles, assuming that version 1 already exists. In other words, the first version of their article was reviewed and published by a knowledge manager, and now we want to allow authors to publish their KB themselves after they make updates to it. 

 

The existing condition on the UI action is: current.workflow_state=='' || gs.hasRole('knowledge_admin')

 

In order to accommodate the new requirement, I have tried the following: current.workflow_state=='' || gs.hasRole('knowledge_admin') || (current.author==gs.getUserID() && current.version>='1')

 

This allows the UI action to show up, but it also shows up when the version is less than 1 (ex. Version .01). I've tried it without the quotes around the number as well, but since the value in the field is a string, it doesn't seem to evaluate it correctly. 

 

I also know that I could use the script portion of the UI action to convert the version to a number and then evaluate it, but I'm hoping to find a way to do this in the condition so that we don't show the UI action if the version is less than 1.

 

Any thoughts on how I can accomplish this?

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please use it as below:-

 

current.version.getDisplayValue()>='1'

 

Please mark my answer as correct based on Impact.

View solution in original post

3 REPLIES 3

Sagar Pagar
Tera Patron

Hi @Casey23,

 

Try this updated conditional scripts -

 

current.workflow_state=='' || gs.hasRole('knowledge_admin') || (current.author==gs.getUserID() && parseInt(current.version) >= 1)

 

Thanks,

Sagar Pagar

The world works with ServiceNow

This didn't seem to work. It actually had the effect of showing the UI action when the value was less than 1. But if the number was greater, it was hidden. Using the other suggestion below seems to work successfully.

current.version.getDisplayValue()>='1'

 

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please use it as below:-

 

current.version.getDisplayValue()>='1'

 

Please mark my answer as correct based on Impact.