IT Process Automation

Expand all | Collapse all

Fetch a string using javascript Regular Expression in ITPAM

  • 1.  Fetch a string using javascript Regular Expression in ITPAM

    Posted 07-14-2017 10:29 AM

    Hi Team,

    I have to fetch a string from a line having a unique defined pattern. I have used "match" function of Javascript Regular Expression and it is working in Javascript simulator but not working using ITPAM Javascript operator.

    I am getting the following error Reason:

    Failed to execute code:
    var a = Process.data1;

     


    var b = a.match(/\d{4}[\/]\d{2}[\/]\d{2}[\-][0-9]+/)

     


    Process.data2= b;


    -- msg.string.expected (#8)

     

    data1 variable of Process contains: "Hi etc Hello 2017/01/04-123 Hello Hi etc ".

     

    Kindly help me out to resolve this.



  • 2.  Re: Fetch a string using javascript Regular Expression in ITPAM

     
    Posted 07-16-2017 10:08 PM

    Hi ankgupta4,

     

    is 'Process.data2' defined as an Array?  Can you access 'b.length' and any of the elements of b after calling 'match'?  Which line in that script is line 8 (from memory, the line count includes the comments that PAM inserts when a javascript error occurs)?

     

    Hope that helps ,

    Regards,

    James



  • 3.  Re: Fetch a string using javascript Regular Expression in ITPAM

    Posted 07-17-2017 12:26 PM

    Hi James Campbell,

     

    The required details are as follows:

    Process.data2 is defined as a String.

    The line 8 is:   Process.data2= b;

    I am not able to access any element of variable b using ITPAM not even b.length. But this regular expression is working well when I have tested it on various online javascript simulators.

    Kindly help me in resolving this or to find any other alternative.

     

    Thanks

    Ankur Gupta



  • 4.  Re: Fetch a string using javascript Regular Expression in ITPAM

    Posted 07-17-2017 03:56 PM

    Assuming b is a string array and Process.data2 is a string (not an array), then:

     

    Process.data2= b[0];



  • 5.  Re: Fetch a string using javascript Regular Expression in ITPAM

    Posted 07-19-2017 02:18 PM

    Hi Lindsay,

    I have executed it and it is working great.

     

    Thankyou

    Ankur Gupta



  • 6.  Re: Fetch a string using javascript Regular Expression in ITPAM

    Posted 07-17-2017 12:06 PM

    var b has to be defined as an array