Custom passParameter function to get 2 returned results on exit
I have a couple questions, I do so appreciate your responses.
Why do you initialize the variable $result to EMPTY instead of " " on your web services example?
The other is I need to return two results on exit instead of one.
On the same web services example you have
Set Variable[$result]
Exit Script[Result:$result]
I need the error message from a PHP variable in case there is an error in the rest response so I want to return $result as well as $error.
I changed the above to
Set Variable[Result;$result]
Set Variable[Error;$error]
Exit script [Result; passParameter("result",$result) & PassParameter("error_message",$error)
I am getting the "result" returned but not the "error_message".
I am using the PassParameter custom function which has the "name" and "value" parameters from Six Fried Rice.
"<:" & Substitute( name; ["="; "/="]; [":"; "/:"] ; [">"; "/>"]; ["<" ; "/<"] ) & ":="
& Substitute( value; ["="; "/="]; [":"; "/:"] ; [">"; "/>"]; ["<" ; "/<"] ) & ":>"
I think it should all work once I can get an error message back as well as the result?
Best,
Janis
here is my code
define("ERROR", "Error");
//rest request to AWS Marketing Services
/*NOTE you must have a free apisigning account to correspond with your own Access Key or this script might not work
//You should add your MerchantID to the variable and uncomment the line????*/
$Access_Key = "AKIAIETJLADYILLAACBA";
// this expression will be used to get the contents of the ASIN field
$ASIN_expression= 'GetField ( "aws_marketing::ASIN")';
// now we use fm_evaluate to get the address
$Item_Id= fm_evaluate($ASIN_expression);
//$Item_Id = 'B000BUR1CY';
//$Item_Id = 'B000BUR1';
//ChangeMe
$allparameter =
//ASSOCIATE TAG
//MerchantId=
"Service" ."=". "AWSECommerceService" ."&".
"AWSAccessKeyId" ."=". $Access_Key ."&".
"Operation" ."=". "ItemLookup" ."&".
"IdType" ."-". "ASIN" ."&".
"ItemId" ."=". $Item_Id ."&".
"Version" ."=". "2009-01-06"
;
$request = file_get_contents("http://free.apisigning.com/onca/xml?".$allparameter);
$parsed_xml = simplexml_load_string($request);
if (strpos($request,ERROR) === false){
$result= $parsed_xml->Items->Item->ItemAttributes->ProductGroup;
$category= (string) $result;
echo $category;
}else{
$request=substr($request,strpos($request,'Errors', (strlen($request)-strpos($request,'Errors'))));
$error=$request;
}
This is a very useful plug-in.
how to use fm_load_functions to get fm_set_variable function
Thank you so much for an anser. I do need two results. One is the result from the rest request which in this case only one field a product category.
The other returned result is an error message if the rest request returns an error .
I will try to implement the plugin get error as well later.
I changed the subscript based on the weather forecast subscript back to ending like your weather forecast returning only the one result the result of the rest request.
Set variable ([$result]
Exit script[Result; $result]
I am trying to return the Amazon error as well using your FM_SET/GET_variable in my code but I don't have that function so I am trying to add the fm_load_functions. I have that in a calc field but I can't figure out how I am supposed to use that calc field to load the functions? I looked in your testbed and example files and didn't find fm_load_functions used anywhere, I didn't find it anyways. Then once I have that fm_set_variable function I can set the variable in the php code
and use the calc field fm_get_variable and use get field contents or something to set a field value to that error variable.
That should do it and I guess I need on top of that a field to set the plug-in errors to. I did notice that the one normal result variable filemaker field from the rest request goes into the field quite nicely but if anything goes wrong with the plugin the error message goes into that same field. If there is a previous value I don't want it written over with an error message but I assume if you capture the plugin error in another field then it won't output to the results field. I have to do an update every week and if there is no new value then I want the old value left alone but I assume if I set up the plugin error function that will go away.
thanks again.
Results and error handling
Hello Janis,
EMPTY is a custom function that I use instead of "" just for readability. I think it's easier to spot than "".
In regards to passing back errors, take a look in the user manual for the fm_set_error function. This allows you to explicitly pass back an error (both a code and an optional description). It was created just for this purpose.
If you need to return multiple results, take a look at fm_set_variable and fm_get_variable. You can use these functions to store and retrieve values in memory. Another approach is to return a snippet of XML that you can then parse using FileMaker functions.
Regards,
Micah