Unable to replace special character in Script include and Business Rules

ideamax
Mega Expert

Hello All,
I am facing a problem in xml creation due to special characters. I am creating xml in script include by using parameters from business rule. There are some string which contains special symbol like (&,') .

To replace them with corresponding html name or html code I am using following code :
mystring.replace("&", "&") or mystring.replace("&", "&")

but , When I save this business rule, it changes the above line to
mystring.replace("&", "&");

Please suggest a way or approach to prevent this .

11 REPLIES 11

john_andersen
Tera Guru

Are you using the XML with SOAP? If so, this shouldn't be a problem. There is a property that you may want to check on in the System Properties list. You would want to make sure the property "glide.soaprequest.unescape_xml_response" is set to "false".

If this is not related to SOAP, then please provide a snippet of code that you are using and I would be happy to check it out.

-John


Hi John,


The property is false but still when i write a script to replace the special character and save it, i face this issue.


PLease advise


The snippet which i used in script include is :


var clean= response.replaceAll('&', '&');


You should be able to use StringEscapeUtils to handle replacing your special characters.



Packages.org.apache.commons.lang.StringEscapeUtils.escapeXml(current.description)


HI ,


I tried to used both package call and JSUtil to escape, but it did not work


I got SAX Exception, prolog not allowed... please advise , below is the snippet:


var sm = new SOAPMessage('function1', 'Query');
            sm.setStringParameter('id',id);
            sm.setStringParameter('Code',Query);
            sm.setStringParameter('Password','123');
            sm.setStringParameter('Username','abc');
            sm.post();



            var k=1;
            var response = sm.getResponse();
           
            while (response == null) {
                              //gs.log("waiting for response ... " + k + " seconds");
                              response = sm.getResponse(1000);
                              k++;


                              if (k > 30) {
                                gs.print("validateClarityAjax Response exceeded 30 serc . " + k + " seconds");


                                      status = "408"; // request timeout
                                      response = "timed out waiting for SOAPProbe response, please check the ECC queue at a later time";
                                      break; // service did not respond after 60 tries
                              }
                  }


                            gs.log('validateClarityAjax : Response:' +response);



                            // var clean=JSUtil.escapeText(response.toString());


                              var clean=Packages.org.apache.commons.lang.StringEscapeUtils.escapeXml(response.toString());



                   
                        var xmldoc = new XMLDocument(clean);



                            projName=xmldoc.getNodeText("//name");
                           
                            gs.log(projName);