How to replace a string with a particular value?

sowmyaj
Giga Expert

Hi All,

I need to replace "YYY" string in "observations" column of "test" table with "location" of an "Opened by" column in "incident" table.

Below is the code to fetch the values containing "YYY" string. Can any one let me know how can I replace the "YYY" value with the location of an opened by person in incident table.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
      var inc=new GlideAggregate('u_test')
      inc.query();
</g:evaluate>
<j:while test="${inc.next()}">
      <j:if test="${inc.u_observations.indexOf('YYY') != -1}">
                              ${inc.u_observations}<br/>
      </j:if>
</j:while>
</j:jelly>

Thanks in advance for your valuable inputs.....

Thanks,

Sowmya

4 REPLIES 4

LearnerSubho
Mega Guru

Hi Sowmya,



Implement a solution like this:



var abc ="abcde";


if(abc.indexOf('cd') != -1){


var temp=abc.slice(0,abc.indexOf('cd'));


var tempTail=abc.slice((abc.indexOf('cd')+2),abc.length);


abc=temp+"FGH"+tempTail;


}



Hope this would help you.



Thanks,


Subhankar


Hi Subhankar,



        Thanks a lot. Your above suggested snippet helped me.....



Thanks,


sowmya.


Welcome Sowmya!


andrew_lawlor
Giga Expert

You can also use the String.replace() function.



For example:



var myString = 'YYY XXX';


var newString = myString.replace('YYY', 'My new value');