This discussion is archived
3 Replies Latest reply: Sep 17, 2013 5:53 AM by user13153726 RSS

In OpenScript I am not able to compare two strings

899459 Newbie
Currently Being Moderated

Hi,

 

I am trying to compare two string in if condition. But it is not going through.

 

My code is:

 

String PATTERN_TYPE = eval("{{db.INPUTS_CREATE_REPRICING_PATTERN.PATTERN_TYPE}}").toString();

String REPRICING_TYPE = eval("{{db.INPUTS_CREATE_REPRICING_PATTERN.REPRICING_TYPE}}").toString();

 

if (PATTERN_TYPE == "Absolute")

  {

       info("Absolute section");

 

       if( REPRICING_TYPE == "FLAT")

            {

 

                 info("Absolute FLAT section");              

             }    

   }

 

Databank is having the values as "Absolute" and "FLAT" only so both the if conditions should have passed and both info's should come. But it is not going inside it.

 

Note: I have also tried without toString() function.

 

Please advice.

 

Regards,

Abhay

  • 1. Re: In OpenScript I am not able to compare two strings
    user13153726 Newbie
    Currently Being Moderated

    Hello Abhay,

     

    Please use below...

     

    In java world strings are compared with equals...

     

    == tests for reference equality.

    .equals() tests for value equality.

     

    String PATTERN_TYPE = eval("{{db.INPUTS_CREATE_REPRICING_PATTERN.PATTERN_TYPE}}").toString();

    String REPRICING_TYPE = eval("{{db.INPUTS_CREATE_REPRICING_PATTERN.REPRICING_TYPE}}").toString();

     

    if (PATTERN_TYPE.equals("Absolute")

      {

           info("Absolute section");

     

           if( REPRICING_TYPE.equals("FLAT")

                {

     

                     info("Absolute FLAT section");            

                 }  

       }

  • 2. Re: In OpenScript I am not able to compare two strings
    899459 Newbie
    Currently Being Moderated

    Hi,

     

    Thanks for the help, it worked perfectly for me. will keep it in learning.

     

    I have one more issue if could help me out.

     

    I have any object :

     

    "/web:window[@title='Repricing Pattern Details -New']/web:document[@name='rhsContent']/web:form[@id='newRepricingPatternRPAT' or @name='repricePatternsForm']/web:select[(@id='selectRPA1' or @name='repricePattern.absoluteRepriceEvent[0].repriceType') and multiple mod 'False']"

     

    in this 'selectRPA1' and [0] the numeric value keep changing on ever time.

     

    How can I handle this to make the value get changed for every loop.

     

    I have used below thing, this is not giving any error to me in script but while execution it is saying " Invalid Object Path".

     

    String OBJ_REPRICING_TYPE = "/web:window[@title='Repricing Pattern Details -New']/web:document[@name='rhsContent']/web:form[@id='newRepricingPatternRPAT' or @name='repricePatternsForm']/web:select[(@id='selectRPA"+LEVEL_ADD+"' or @name='repricePattern.absoluteRepriceEvent["+LEVEL+"].repriceType') and multiple mod 'False']";

     

    Thanks in advance.

     

    Regards,

    Abhay

  • 3. Re: In OpenScript I am not able to compare two strings
    user13153726 Newbie
    Currently Being Moderated

    Hi Abhay,

     

    If the IDs are changing sequentially then passing loop variable should work.  By looking at your code what your application might be starting index "1" for 'selectRPA1'  and index "0" for "absoluteRepriceEvent[0]".  Can you also let me know what is the initial LEVEL_ADD and LEVEL values that you are passing to the statement.  Also your code snippet would be helpful.

     

    for (int i = 0; i <= 10; i++)

    {

         String OBJ_REPRICING_TYPE = "/web:window[@title='Repricing Pattern Details -New']/web:document[@name='rhsContent']/web:form[@id='newRepricingPatternRPAT' or      @name='repricePatternsForm']/web:select[(@id='selectRPA"+LEVEL_ADD+"' or @name='repricePattern.absoluteRepriceEvent["+LEVEL+"].repriceType') and multiple mod 'False']";

    }

     

    NOTE:  If you are not using this in the loop then you should consider doing a wildcard or regex.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points