Announcement

Collapse
No announcement yet.

returning the value of a variable in javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • returning the value of a variable in javascript

    Hi folks
    I have a doubt.
    I have made a script to read the clinical history number, (peide) and remove some numbers.

    The script is as follows
    var longitud=$('PEIDE').length();
    for (var i = 0; i< $('PEIDE').length; i++)
    {
    var caracter = $('PEIDE').charAt(i);
    if( caracter == "X" || caracter == "x") {
    var res = str.substring(0, i);
    globalChannelMap.put('res')
    return false;
    } else {

    return true;
    }


    and after that a message builder step to integer that $('res') to pid field 5.

    Problem is... not funcioning. Not a single error so I guess I'm doing something wrong.

    Can you please help?

  • #2
    Originally posted by ferdinand View Post
    Hi folks
    I have a doubt.
    I have made a script to read the clinical history number, (peide) and remove some numbers.

    The script is as follows
    var longitud=$('PEIDE').length();
    for (var i = 0; i< $('PEIDE').length; i++)
    {
    var caracter = $('PEIDE').charAt(i);
    if( caracter == "X" || caracter == "x") {
    var res = str.substring(0, i);
    globalChannelMap.put('res')
    return false;
    } else {

    return true;
    }


    and after that a message builder step to integer that $('res') to pid field 5.

    Problem is... not funcioning. Not a single error so I guess I'm doing something wrong.

    Can you please help?
    Wouldn't you need something like this...

    Code:
    globalChannelMap.put('res', res);
    Then you could call $('res')

    Comment


    • #3
      nothing happens when I call $('res')
      empty field
      I use
      message builder tmp['QRD']['QRD.8']['QRD.8.1']
      mapping $('res')

      It should be something in concept that i'm not doing right, I know
      ...

      Comment


      • #4
        Code:
        var longitud = $('PEIDE').length();
         for (var i = 0; i < $('PEIDE').length; i++) {
             var caracter = $('PEIDE').charAt(i);
             if (caracter == "X" || caracter == "x") {
                 var res = str.substring(0, i);
                 globalChannelMap.put('res')
                 return false;
             } else {
                 return true;
             }
        }
        You're only reading the first character before your script returns.

        You say message builder so I'm assuming this is in a transformer step. You don't need the returns at all if that's the case.

        The globalChannelMap.put needs two arguments. It's never getting called, because it would definitely throw an error if it was.

        Use this instead:
        Code:
        var longitud = $('PEIDE').length();
        for (var i = 0; i < $('PEIDE').length; i++) {
            var caracter = $('PEIDE').charAt(i);
            if (caracter == "X" || caracter == "x") {
                var res = str.substring(0, i);
                globalChannelMap.put('res', res)
            }
        }

        Comment


        • #5
          Yes this is a transformer step

          I have done the mods you suggested and still doesn't work.

          If only I found an example of use of variables in javascript...

          Comment


          • #6
            Originally posted by ferdinand View Post
            If only I found an example of use of variables in javascript...
            Here's a good spot for that: https://developer.mozilla.org/en-US/...ript/Reference

            Looked over your code a little more and came up with this:
            Code:
            var peide = new String($('PEIDE'))
            for (var i = 0; i < peide.length; i++) {
                var caracter = peide.charAt(i);
                if (caracter == "X" || caracter == "x") {
                    var res = peide.substring(0, i);
                    globalChannelMap.put('res', res)
                }
            }
            The code was calling $ more than needed, referencing a variable that was undefined (str), and creating unused variables (longitud).

            Here's another way of doing that thing:
            Code:
            var peide = new String($("PEIDE"))
            var match = peide.match(/(.*)x.*/i);
            globalChannelMap.put("res", match? match[1]: peide);
            Last edited by plew; 09-29-2015, 01:32 PM.

            Comment


            • #7
              Originally posted by plew View Post
              Here's a good spot for that: https://developer.mozilla.org/en-US/...ript/Reference

              Looked over your code a little more and came up with this:
              Code:
              var peide = new String($('PEIDE'))
              for (var i = 0; i < peide.length; i++) {
                  var caracter = peide.charAt(i);
                  if (caracter == "X" || caracter == "x") {
                      var res = peide.substring(0, i);
                      globalChannelMap.put('res', res)
                  }
              }
              The code was calling $ more than needed, referencing a variable that was undefined (str), and creating unused variables (longitud).

              Here's another way of doing that thing:
              Code:
              var peide = new String($("PEIDE"))
              var match = peide.match(/(.*)x.*/i);
              globalChannelMap.put("res", match? match[1]: peide);

              Thanks thanks thanks!!!
              Finally it works!

              So, Can I use the variables directly in javascript? it seems not.
              Have you used any tool to debug it?

              Yours faithfully,

              Comment

              Working...
              X