indexOf() not working in client script

surbhi_123
Tera Expert

I have an onChange client script where value is getting fetched from script include. I want that the value that is getting from script include to populate in the variable only if it's value starts with OPE. 

surbhi_123_0-1694614089015.png

But this is not updating any value, if I remove the line no 18 it fetches the correct value and sets to the variable

1 ACCEPTED SOLUTION

Hi,
You should return the display value of the cost center instead of SYS_ID.

Sample code for your Script Include

gr.getDisplayValue('cost_center');

 

 


Thanks and Regards,

Saurabh Gupta

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

Hi @surbhi_123 

 

Can you please reverify what type of data answer is storing. Just add alert(answer) after line no. 17 and check.

 

Please Mark My Response as Correct/Helpful based on Impact

Krishna Sharma

surbhi_123_1-1694616430855.png

 

Hi,
You should return the display value of the cost center instead of SYS_ID.

Sample code for your Script Include

gr.getDisplayValue('cost_center');

 

 


Thanks and Regards,

Saurabh Gupta

Community Alums
Not applicable

Hi @surbhi_123 ,

You are getting Sys ID that's why indexOf is not working. To fix this you should return display value from script include or replace 'OPE' with the Sys ID.

 

Please Mark My Response as Correct/Helpful based on Impact

Krishna Sharma

 

 

Siva Jyothi M
Mega Sage

Hi @surbhi_123,

 

There is a curly brace missing after if statement, can you set the value inside the if statement and try.

if(answer.indexOf('OPE')>-1){
g_form.setValue('cost_center', asnwer);
}

Please Mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.