After a quick google search I found this simple javascript function which will get you half way there:
Modified slightly, here’s the basic code:
var str = "RSSSSTTZZ"
function letterCount(str){
var s= str.match(/([a-zA-Z])\1*/g)||[];
return s.map(function(itm){
return [itm.length, itm.charAt(0)];
});
}
const arr = letterCount(str)
console.log(arr.toString().replace(/1/g, '').replace(/,/g,''))
To make the above actually usable, you’d replace the first line with pulling in data from a particular record, and replace the last line with a function to actually update the record. There are several examples of both throughout these forums, but I can help guide how to do it if you need further assistance.
Thank you so much for your quick response, Kamille_Parks!
So I was able to get your script to work perfectly with the output showing up in the console log.
Now I’ve set up an automation when the field “FinalDiscountCodeString” is modified in the “Product” table, the script will run and put the result in the “FinalDiscountCodeScriptRun” field also in the “Product” table. Here’s what I was able to come up with but I’m keep getting errors:
let table = base.getTable(“Product”);
let str = input.config();
function letterCount(str){
var s= str.match(/([a-zA-Z])\1*/g)||[];
return s.map(function(itm){
return [itm.length,itm.charAt(0)];
});
}
const arr = letterCount(str)
table.updateRecordAsync.FinalDiscountCodeScriptRun(arr.toString().replace(/,/g,’’).replace(/1/g,’’))
Being a novice at scripting I know that this can be done but I seem to be beating a dead horse on new ideas for what to try to get the code to go through…any pointers, are greatly appreciated.
Thanks again!
Thank you so much for your quick response, Kamille_Parks!
So I was able to get your script to work perfectly with the output showing up in the console log.
Now I’ve set up an automation when the field “FinalDiscountCodeString” is modified in the “Product” table, the script will run and put the result in the “FinalDiscountCodeScriptRun” field also in the “Product” table. Here’s what I was able to come up with but I’m keep getting errors:
let table = base.getTable(“Product”);
let str = input.config();
function letterCount(str){
var s= str.match(/([a-zA-Z])\1*/g)||[];
return s.map(function(itm){
return [itm.length,itm.charAt(0)];
});
}
const arr = letterCount(str)
table.updateRecordAsync.FinalDiscountCodeScriptRun(arr.toString().replace(/,/g,’’).replace(/1/g,’’))
Being a novice at scripting I know that this can be done but I seem to be beating a dead horse on new ideas for what to try to get the code to go through…any pointers, are greatly appreciated.
Thanks again!
To do this via an Automation you will need two Input Variables: one for str
(the {FinalDiscountCodeString}
field value from the trigger record), and one for recordID
(the trigger record’s id)
So to pull in these variables properly, change:
let str = input.config();
to
let {recordID, str} = input.config();
And change:
table.updateRecordAsync.FinalDiscountCodeScriptRun(arr.toString().replace(/,/g,’’).replace(/1/g,’’))
to:
await table.updateRecordAsync(recordID, {
"FinalDiscountCodeScriptRun": arr.toString().replace(/,/g,’’).replace(/1/g,’’)
}