Jump to content
Server Maintenance This Week. ×

Calling a script from a Web Viewer on WebDirect


mz123

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

Recommended Posts

Hi there! Long time. :)

Question about Carafe on WebDirect. With the Google Maps bundle, a script is called when the user clicks on the marker. This works perfectly in Pro (woot!). But if I try through WD, the FMP URL wants to open up FM, the app, instead of running the script within the WD instance. Is there a way around this? In short, I'm trying to open a card window (v19) when the user clicks on a marker.

 

Thanks for all of your hard work on this.

Link to comment
Share on other sites

21 hours ago, mz123 said:

With the Google Maps bundle, a script is called when the user clicks on the marker. This works perfectly in Pro (woot!). But if I try through WD, the FMP URL wants to open up FM, the app, instead of running the script within the WD instance. Is there a way around this?

Yes! Bundles that are compatible with versions of FileMaker Server less than 19 do not have the option of using the new FileMaker.PerformScript function they added.

So far all the bundles we've got published up here are created to support the FMP URL technique. I'll let you know when we have a WebDirect 19 compatible version. Are you using the Carafe Add-on or the Kitchen style of deployment?

Link to comment
Share on other sites

Hi Martha,

The change to support FileMaker.PerformScript in 19 is very simple, so I went ahead and updated the GoogleMaps bundle to 3.0.5 with support for a new config option "useFmpUrl" which defaults to "true". If you change that to "false" you will get the new behavior.

Please note, in testing this I discovered a fixed issue in 19 which we had previously needed to work around in WebDirect by base64 encoding the dataurl. This still worked fine, but as it turns out, broke the PerformScript feature. So now there is version detection, so it can work properly in both 19 and earlier versions. You'll need to deploy with Carafe Add-on 0.3.0+ or Carafe Kitchen 3.1.3+ which I just pushed up to https://carafe.fm/downloads/ a few minutes ago.

Link to comment
Share on other sites

  • 1 year later...

I saw this article and have exactly the same issue in a google cluster map implementation.  Thanks for all the awesome stuff you have posted and contributed.  

In my instance I'm showing a google cluster map in a web viewer in a WebDirect solution hosted on FMS 19.3.2.203

I'm using the FileMaker.PerformScript function to run the script which finds the record.  Of course it works great in FMPro, but in WebDirect it tries to open the FMPro App instead of just going to the record. I know in the past there were all kinds of pretty hairy workarounds to make this happen, because the webviewer is originating from a different domain and there were different WebDirect sessions, etc.  Basically I just gave up on it.

But I thought in FMS19 there was an easier way to be able to click a link in the webviewer in WebDirect and have it go to the record.  Am I missing something?  Can you please point me in the right direction?

Thanks,
David

Link to comment
Share on other sites

Basically what I'm saying is that setting that "useFmpUrl" variable to "false" did not change the behavior for me and make it work in a webviewer in web direct.  Nothing happens. It works in FMPro when set to true, but never in WebDirect. 

This seems to be the pertinent portion of code in the "Insert Text" step of the Carafe bundle script:

      function sendToFmp(data) {
        var parameter = JSON.stringify(data)
        var useFmpUrl = '__useFmpUrl__' === 'true' ? true : false ;
        if (useFmpUrl) {
          var theURL =
            "fmp://$/__fileName__?script=__scriptName__&param=" +
            encodeURIComponent(parameter);
          window.location = theURL;
        } else {
            FileMaker.PerformScript('__scriptName__', parameter);

What am I missing?

Link to comment
Share on other sites

It definitely works with WebDirect as long as you're using a supported version of FMS 19 (important: Server must be 19+ and bundle must be 3.0.5+). In the snippet you shared from the template.carafe file, it shows the condition which switches between the legacy fmp url feature and the newer FileMaker.PerformScript option. If it's still firing the fmpurl, you most likely are not setting the config properly. The useFmpUrl parameter should be omitted or set to false which will cause it to use the new behavior. If you explicitly set useFmpUrl to true, it will use the fmp url instead.

2 hours ago, DGSoz said:

how to make the map link work to go to a record in WebDirect

To be clear, making it go to a record requires scripting that behavior in a FileMaker script. The JavaScript function only passes along the click event with an id parameter for the pin that has been clicked.

It sounds like you already know this, if you have it working as you desire in FileMaker Pro, and it's down to getting the script call to work in WebDirect, but just confirming assumptions.

Edited by dual_mon
Link to comment
Share on other sites

Hi dual_mon, and thanks for your response.

I'm running FMS 19.3.2.203.  I don't know what you mean by "Bundle", neither did my file host.  Can you please clarify?  Happy to check that.

Yes, I was explicitly setting the useFmpUrl condition to "false".  Actually I played with switching it back and forth just to try all conditions.  But I understood from your previous post here that setting it to false would produce the result of calling the specified script when clicking the map pin in the web viewer in web direct.  And thus I could pass the id parameter and find that record, or whatever I needed to do.

No worries clarifying the script function.  Right now the called script just shows a dialog with the passed parameter. But currently this only works in FMPro.  Once I get it to work in WebDirect I'll wire it up to do what I actually need.

I basically copied and pasted all the code from your excellent step by step video.  (map loader script below).  Everything works great, except this one link clicking thing on WebDirect.

I have "Allow JavaScript to perform FileMaker scripts" checked on the web viewer.  I even have "Allow URLs to run FileMaker scripts (fmurlscript)" checked in the file security.

Any ideas?  What else should I check.

 

 

Screen Shot 2022-05-18 at 8.56.32 AM.png

Link to comment
Share on other sites

Ok, totally my fault.  I found my silly error.  I had two layouts because I was trying two different mapping methods, and on one of them the webviewer was NOT set to "Allow JavaScript to perform FileMaker scripts"  Once I fixed that the script was successfully called by the pin click.

I also realized that "Bundle" referred to Carafe, not FMS.  I'm using Bundle V3.0.5  by the way.  Sorry for the confusion. 

Separate question though.  On the other mapping method I tried, clicking the map pin shows the record info in a small bubble, and clicking THAT info link initiates the script (though it does not work in web direct).  This info bubble would be my preferred behavior.  On the carafe version clicking the pin initiates the script so the user doesn't get to really see the record info first.  Hovering over the pin shows a small preview of the record info, but I'd prefer the larger nicer looking info bubble, and then letting the user click the record name there to go to that record, or instead choose another pin.

Is there a setting I can change in the bundle code to make it exhibit this behavior?

Link to comment
Share on other sites

Looking in the other code it seems like it may have something to do with:

google.maps.event.addListener (marker, 'click', function () {
 
	    var markerTitle = marker.getTitle();
                var markerID = this.customInfo;
		var myTitle = "<a href=fmp://$/MYFILE?script=MYSCRIPT&param="+markerID+ "><h3>" + markerTitle + "</h3></a>";


		var infowindow = new google.maps.InfoWindow({
  			  content: myTitle
		  }); 
//  window.location = theURL ;

		infowindow.open(map, marker);

I see " window.location = theURL;" in the Carafe code, but nothing about "InfoWindow".  or a "listener" for the click function.

Full disclosure I'm more of a reverse-engineer coder than a from-scratch coder. Is there some code I could add or change in the carafe code to make it exhibit this behavior?

Is there a way I could drop the above code in there somehow without breaking everything?

 

Link to comment
Share on other sites

In the Carafe code I see: 

      function markerClosure(marker) {
        marker.addListener("click", function() {
          sendToFmp(marker.id);

Presumably this might be where I could change the behavior to show the info window?  And then let that link trigger the FileMaker script.  But I'm hesitant to cut and paste code in this case.  Like I said, I don't want to break something that is working.  Just want to add the info window behavior.

Link to comment
Share on other sites

You’re on the right track, but you can’t just copy/paste the second example without understanding and modifying it. To make modifications to the JavaScript you should probably try to collaborate with someone who knows JavaScript, or look into taking a course on it yourself.

Link to comment
Share on other sites

This topic is 702 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.