Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Insert from URL to Post multiple line invoice

Featured Replies

Hi there,

I have a bit of a challenge and was wondering if anyone has come across anything similar and could guide me in the right direction.

I have a invoice line table where there are multiple records for one invoice.

I need to post those multiple lines using the insert from URL function in one single post.

Now before I go further.

I am currently using the insert from URL in a number of scripts for the exact same purpose but in each case I am only ever posting one record at a time. This works just fine. So I'm not a complete newbie at this function.

What I can't seem to get my head around is how I can get multiple records into my http post formula. 

a few options I'm contemplating:

  • Export the data to a CSV then import the CSV into a single field (if it's possible) then somehow try and extract the data and insert it in the post url
  • Loop through the records, inserting the contents into another field eg. global field then build the URL using the data in the global field.

Are any of these viable or does anyone have any better solutions for this?

 

 

Why not query data via SQL command?

You're not telling us how the URL needs to look, so it's hard to say what's the best way to build it. In general, you can use the List() function to get a list of (non-empty) values in each related field. Also, if you're looping, you can save resources by using a script variable to build the URL.

  • Author

Thanks for your replies.

@MonkeybreadSoftware I'm not very familiar with SQL command. I'd have to research that a bit to see how I can achieve what I'm after.

@comment Here is a sample of the http post I need to create:

"httppost://mydomain.com/stockadjustsale.php?register_id=123456" &

"&customer_id=927b583f-ff6f-11e3-a0f5-b8ca3a64f8f4" &

"&user_id=9876543"  &

"&status=SAVED" &"&

note=Refurb%20ID:%20217"  &

"&product_id=hag23468qsj73e"  &

"&quantity=1" &

"&price=9.09" &

"&tax=0.91" &

"&tax_id=79c237d1-c534-11e3-a0f5-b8ca3a64f8f4" &

"&product_id=jhsyuw374635"  &

"&quantity=1" &

"&price=16.36" &

"&tax=1.64" &

"&tax_id=79c237d1-c534-11e3-a0f5-b8ca3a64f8f4" &

"&key=123456789"

This is an example with two line items.

I'll explore your suggestion to use a variable to build the URL as I'm looping through the records. In most cases it's only ever going to be between 1 and 5 records maximum.

The first part is the actual invoice details, then the line items follow.

As I mentioned, I'm currently post a single line item which works just fine, the difference with the single line item is that I'm just adding the fields in directly instead of the values. eg:

"httppost://mydomain.com/stockadjustsale.php?register_id=" & RefurbItems::_kf__SaleRegister_ID &

"&customer_id=927b583f-ff6f-11e3-a0f5-b8ca3a64f8f4" &

"&user_id="  & RefurbItems::SoldBy &

"&status=SAVED" &

"&product_id=" & RefurbSparePartsCost::id &

"&quantity=1" &

"&price=" & RefurbItems::SoldAmountExTax &

"&tax=" & RefurbItems::SoldAmountTax &

"&tax_id=79c237d1-c534-11e3-a0f5-b8ca3a64f8f4" &

"&note=Refurb%20ID:%20" & RefurbItems::RefurbItemsID &

"&key=" & ApplicationSettings::VendAPIKey

 

Thanks again for your input.

Mark

I'm not sure that will ever work on the other end - a POST sets values to name = value - so if you have two that are the same, one will overwrite the other when being processed...

You could of course try that manually to check what happens:

httppost://mydomain.com/stockadjustsale.php?register_id=123456&customer_id=927b583f-ff6f-11e3-a0f5-b8ca3a64f8f4&user_id=9876543&status=SAVED&note=Refurb%20ID:%20217&product_id=hag23468qsj73e&quantity=1&price=9.09&tax=0.91&tax_id=79c237d1-c534-11e3-a0f5-b8ca3a64f8f4&product_id=jhsyuw374635&quantity=1&price=16.36&tax=1.64&tax_id=79c237d1-c534-11e3-a0f5-b8ca3a64f8f4&key=123456789

  • Author

@webko Thanks for your input - It's actually posting to a custom API that we've created in PHP so we can handle the programming part we may had a seperator line that tell the system it's a new line or something similar.

Still not seeing how that works. 

<?php
  $product = $_POST['product_id'];
?>

How can it determine which of the multiple product_id being passed is which?

  • Author

Because we can control the API I can post any format I like. The trouble is I just can figure out how to get the data I need into the URL.

Another option I was considering was to export to xml, then see if I could import the content of the xml to a field.

I'm just not sure what the best way to handle this is.

 

Since you control the 'web service' that you are talking to, I would suggest that you construct a json format of the data that you need to send, with arrays for the multiple elements. And then just POST the json.  You can then have your web service work with that json.  Make your web service either a RESTful web service that can consume json or a SOAP one that expects XML.

No need to export anything from FM, just construct the json (or XML if you want) in the script based on the data. 

9 hours ago, webko said:

Still not seeing how that works. 


<?php
  $product = $_POST['product_id'];
?>

How can it determine which of the multiple product_id being passed is which?

You can pass multiple parameters with the same name as long as you pass them as an array. So like...

name[1]=Homer&name[2]=Bart

Then you can loop through that array to get the values in your web script. In php you can use a foreach to loop through.

In fact, I sometimes pass delimited data in this way to keep the payload size down and break it out in php as a multi-dimensional array.

so r[1]=Homer,Simpson,Dad&r[2]=Bart,Simpson,Son

becomes...
 

foreach ($_REQUEST['r] as $key => $value) {

  $items = explode($delimiter, $value);
  $this_first = $items[0];
  $this_last = $items[1];
  $this_role = $items[2];

# do something with this data here...

}

Hope this helps,
Mike

 

 

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.