- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 08:20 AM
In one of Catalog item, I created a single line text variable with Validation Regex as currency.
I need if condition if the Variable value >$5000 should go to approval task if no then no approval
I created condition like below screenshot and its not working as expected, approval is going <$5000 as well
Any once can suggest what is wrong with this?
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 07:14 AM
You should be using a Script with the Advanced box checked, which means you need to delete the Condition so that the script runs without being influenced by the condition. If it still doesn't work with the latest script I proposed with the temporary log to confirm the value, (which works in a background script using hard-coded values as your test case) try removing the $ as @mahemoodhus suggested, but in your script it would just be:
answer = ifScript();
function ifScript() {
var amt = parseInt(current.variables.expected_amount.toString().replace('$', '');
workflow.info('amount is ' + amt);
if (amt <= 5000) {
return 'yes';
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 07:14 AM
You should be using a Script with the Advanced box checked, which means you need to delete the Condition so that the script runs without being influenced by the condition. If it still doesn't work with the latest script I proposed with the temporary log to confirm the value, (which works in a background script using hard-coded values as your test case) try removing the $ as @mahemoodhus suggested, but in your script it would just be:
answer = ifScript();
function ifScript() {
var amt = parseInt(current.variables.expected_amount.toString().replace('$', '');
workflow.info('amount is ' + amt);
if (amt <= 5000) {
return 'yes';
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 09:05 PM
Looks this worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 04:55 AM
- Hi surajsukuma,
you can use a Catalog Item Workflow with proper conditions or write a Scripted Condition. Here's how you can address this issue:
- Open the approval activity in the workflow.
- Add a Scripted Condition and use the following script
- (function executeRule(current, gWorkflow) {
// Get the value of the variable
var amount = current.variables.your_variable_name; // Replace 'your_variable_name' with the actual name of your variable
// Remove the '$' symbol and convert to a number if needed
var numericAmount = parseFloat(amount.replace('$', '').trim());
// Check if the amount is greater than $5000
if (numericAmount > 5000) {
return true; // Trigger approval
}
return false; // Skip approval
})(current, gWorkflow); - Must try this code to in your instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 07:11 AM
I already had run script to create Approval task, is it possible to include in this script itself
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 05:02 AM
try this
answer = ifScript();
function ifScript() {
var amt = current.variables.expected_amount.getValue();
if (amt <= 5000) {
return 'yes';
}
return 'no';
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader