- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2023 12:06 PM
I want to count number of characters entered in a string field.
Divide the total number of characters by 3.5 and store it in an Integer field.
I created a business rule in update/insert. I'm stuck on writing script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2023 02:11 PM
Hey Mate,
One minor observation, you have multiplied by 3.5 while the question asked for Division
So the script changes to
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var noChars = current.string_field_name.length;
var multipleVar = noChars / 3.5;
gs.info("myBusinessRule: multipeVar = " + multipleVar);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2023 01:11 PM - edited ‎09-17-2023 01:31 PM
Hi Ram108,
Try:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var noChars = current.string_field_name.length;
var multipleVar = noChars * 3.5;
gs.info("myBusinessRule: multipeVar = " + multipleVar);
})(current, previous);
if you store the result in an integer field, you will loose precision when an odd number of characters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2023 02:11 PM
Hey Mate,
One minor observation, you have multiplied by 3.5 while the question asked for Division
So the script changes to
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var noChars = current.string_field_name.length;
var multipleVar = noChars / 3.5;
gs.info("myBusinessRule: multipeVar = " + multipleVar);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2023 11:51 PM
Thanks for your reply both of you.
I tried in background script. It returns for noChars
undefined
var gr = new GlideRecord("x_agm_open_int_configuration");
gr.addQuery("sys_id","9431bddc1ba3a91048d90fa9cc4bcb3d");
gr.query();
if(gr.next()){
var noChars = gr.maintain_template.length;
var multipleVar = noChars / 3.5;
gs.info("myBusinessRule: multipeVar = " + noChars);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2023 12:15 AM
gr.maintain_template.toString().length;
just added toString and it is working. Thanks both of you.