Count how many times a specific word is in a string field

Wasd123
Tera Expert

I have an integration what is raising a catalog item, and here I would need a business rule to count how many times do we have a specific word in the variables called "External Description".

 

I can fetch the value from that variable "

 var text = scReqItem.variables.external_description;"
 
but how can I check how many times the word "
"CustomerLineNumber" appears in this text?
1 ACCEPTED SOLUTION

Wasd123
Tera Expert

okay, figured it out.

 

var count=0;
var c=0;
var temp='';
var scReqItemTaskCount = new GlideRecord("sc_req_item");
scReqItemTaskCount.addEncodedQuery(some querry);
gs.print(scReqItem.sys_id);
scReqItemTaskCount.query();
while (scReqItemTaskCount.next()) {
temp=scReqItem.variables.external_description;
c = (temp.match(/CustomerLineNumber/g) || []).length;
count = count+c;
c=0;
  }
gs.print(count)

View solution in original post

1 REPLY 1

Wasd123
Tera Expert

okay, figured it out.

 

var count=0;
var c=0;
var temp='';
var scReqItemTaskCount = new GlideRecord("sc_req_item");
scReqItemTaskCount.addEncodedQuery(some querry);
gs.print(scReqItem.sys_id);
scReqItemTaskCount.query();
while (scReqItemTaskCount.next()) {
temp=scReqItem.variables.external_description;
c = (temp.match(/CustomerLineNumber/g) || []).length;
count = count+c;
c=0;
  }
gs.print(count)