Jump to content

Insert from URL to Post multiple line invoice


This topic is 2623 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This topic is 2623 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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