challenges with IndexOf function

sainath3
Mega Guru

Hi Team,

 

Am facing challenges with the IndexOf function.

 

below is the requirement: 

 

Based on the Short description Assignment group should be updated.

below are the keyword and assignment groups.

If the short description contains any below keywords respective assignment group should populate in the assignment group field.

KeywordAssignment group
Late chargesAccount department
Smart chargesSNTP department
Site Visit chargesSNTP department
Other chargesAccount department

I have Created two different system properties for Above Assignment groups.

Properties are: 

Account Department: Late charges, Ot.her Charges

SNTP Department: Smart charges, Site Visit charges.

 

My code:

Var circuitReference="Issues are related to Late charges"

Var exclude_identifier = gs.getProperty("Account department").toLowerCase().split(",");
circuitReference = circuitReference.toLowerCase();
for (var key in exclude_identifier) {
if (circuitReference.indexOf(exclude_identifier[key]) != -1) {
current.u_assignment_group = 'Account department';
}
}

var exclude_identifier1 = gs.getProperty("SNTP Department").toLowerCase().split(",");
for (var key in exclude_identifier1) {
                    if (circuitReference.indexOf(exclude_identifier1[key]) != -1) {                                      
current.u_assignment_group = 'SNTP department';                          
                      }
                    }
                }
 
Output is:  SNTP department.
Expected output is: Account department.
RCA: Charges keyword is available in both the groups.
 
Please help me here .....

 

10 REPLIES 10

Brad Bowman
Kilo Patron
Kilo Patron

I'm having trouble following this.  Please post the entire actual script using the insert code </> icon, and the values of both system properties and we'll get you sorted.

Hi Brad,

 

I have modified my query; can you check it now

There is something missing with the examples you are providing.  It doesn't matter that 'charges' appears multiple times, in both system properties.  The indexOf method is searching the string "issues related to late charges" for the appearance of the phrases/character strings (not individual words/partial match) 'late charges', 'other charges', 'smart charges', and/or 'site visit charges'.  Since there is not a value in either property for just the word 'charges', the string from the correct property will always be identified.

 

I confirmed this in my PDI by creating two system properties with the names and values given.  I then created a Fix Script using your script with gs.print lines in place of the field assignment (and correcting the lowercase var appearances).  The expected result was always returned, for iterations changing the circuitReference string also.    

Simon Christens
Kilo Sage

Hi

The reason it wont work is because you are making circuitReference tolowercase but do dont do it with your property values.

 

 

circuitReference = circuitReference.toLowerCase();
if (circuitReference.indexOf(exclude_identifier[key]) != -1) {

 

 

So try and change it to the below for both of the if's

 

 

if (circuitReference.indexOf(exclude_identifier[key].toLowerCase()) != -1) {