Method Community

 

Loop string of comma separated values?

Last post 06-20-2019 1:11 PM by wombatmaster. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 03-29-2015 6:11 PM

    Loop string of comma separated values?

    I was wondering if there was a way to loop through a string of comma separated values, like a foreach statement, assigning the iteration value to an action result?

  • 03-30-2015 10:27 AM In reply to

    Re: Loop string of comma separated values?

    Hi furrywombat,

    This may or may not be possible depending on what you're trying to do. Could I get a bit more info on your use case?

    Let me know.

    - Justin

    Justin Henderiks
    Technical Sales Specialist
    Method Integration Inc.
    Toll Free: 1.888.925.6238
    Local and overseas: 416.847.0400
    Fax: 416.640.6027
    E-mail: j.henderiks@method.me
  • 03-30-2015 10:47 AM In reply to

    Re: Loop string of comma separated values?

    Justin,

    I'm working on a concept where we would call a web service (ours) from Method. The web service would return a comma-separated list of values that would be specific to, say, for example, the Invoice table. I would like the returned value to be parsed as an array and then loop through each individual value... something like this:

    Call web service https://www.domain.com/webservice.whatever?var1=x,var2=y and assign return value to action result webServiceResponse

    Web service response = 1,2,3

    Explode webServiceResponse to aray.

    foreach (webServiceResponse as webServiceEach) {

        do something with webServiceEach

    }

    Make sense?

  • 03-30-2015 1:12 PM In reply to

    Re: Loop string of comma separated values?

    Answer

    FW,

    You would have to do something like this:

    1. Character Function - Find Character to find the location of the first comma
    2. Subtract value from step 1 by 1
    3. Substring the first value by using Character Function - Get Left with the value from step 2
    4. Do something with the value
    5. Substring the remainder of the string by adding 2 to the value from step 3 and using Character Function - Get Right with that value
      • You should now be left with a list of values that does not contain the first value from the initial list
    6. Rinse and repeat

    Hope this helps.

    - Justin

    Justin Henderiks
    Technical Sales Specialist
    Method Integration Inc.
    Toll Free: 1.888.925.6238
    Local and overseas: 416.847.0400
    Fax: 416.640.6027
    E-mail: j.henderiks@method.me
  • 04-04-2015 6:19 PM In reply to

    Re: Loop string of comma separated values?

    Awesome, thanks Justin.

  • 06-14-2019 9:14 AM In reply to

    Re: Loop string of comma separated values?

    How do you do the "Rinse and repeat" part? There doesn't seem to be any loop that isn't tied to either a grid or a table. Not even so much as a goto function.

  • 06-17-2019 3:00 PM In reply to

    Re: Loop string of comma separated values?

    The only way to effectively accomplish this within Method without losing your hair in the process is to develop your own API. Then, push the request using a web service call, chop/stir-fry/bake/garnish, what have you, using an actual programming language with real flexibility, and serve back to Method in whatever form is desired or requested.

  • 06-19-2019 9:33 AM In reply to

    Re: Loop string of comma separated values?

    Are you saying that there is a way to write in PHP, or some other languate on the Method platform? Because my problem is taking a multi-record JSON response (with an unknown number of records) from a web service, and looping through it to load a custom Method table. Obviously calling another external web service isn't going to help with this.

  • 06-20-2019 1:11 PM In reply to

    Re: Loop string of comma separated values?

    That being the case, I would suggest creating a reporting module on your site and iframing it into Method using a Web Page Window object. If needed, you can add custom CSS by dropping a label-type field into a hidden section, creating a custom table containing long text fields you can use for your CSS, then applying to the hidden label on page load using the Advanced button to the right of the screen name in the editor.

    This is all assuming you're using the Classic version. Have not done much with New yet personally. Lacking the ability to utilize custom SQL lookups, is useless to us.

Page 1 of 1 (9 items)