The CreatorCon Call for Content is officially open! Get started here.

Character count in string fiel

Ram108
Kilo Expert

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.

1 ACCEPTED SOLUTION

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);
-Anurag

View solution in original post

5 REPLIES 5

Bert_c1
Kilo Patron

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.

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);
-Anurag

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);
}

gr.maintain_template.toString().length;

 

just added toString and it is working. Thanks both of you.