Passing Data to an External Application
When viewing a record, you can pass data to an external application, using a simple query to read the current fields and to pass them to the external application. In the following example, data is passed from the current module (Module ID 7) to the external application with the App URL testsales://spots/.
<html><head><title>ExternalAppExample</title><script type="text/javascript"> var externalAppUrl; function openExternalApp(rows){ externalAppUrl = "testsales://spots/"; if(rows.length > 0){Â externalAppUrl += "Call Id=" + rows[0]._6.uid + "&Contact=" + rows[0]._6.CALREF1 + "&DUE DATE=" + rows[0]._6.CALTXT01 + "&START TIME=" + rows[0]._6.CALSTARTDATE + "&STATUS=" + rows[0]._6.CALTXT07 + "&SUBJECT=" + rows[0]._6.CALDESCRIPTION;Â } return "[ {\"action\":\"goToURL\", \"url\":\"" + externalAppUrl + "\"}]"; } </script></head><body></body></html>
where:
- var externalAppUrl; creates an externalAppUrl variable.
- function openExternalApp(rows) defines the function to open the external application, and prepares the rows to pass from the current record to the function.
- "testsales://spots/" is the first value entered into the externalAppUrl variable, so it contains some data.
- if(rows.length > 0){ inserts an if query so that the action is only completed if the current record contains data.
- When all the fields are added to the externalAppUrl variable, the fields being written to are inserted, followed by the field being sent from the current object (Module ID 6). The code used is as follows:
externalAppUrl += "Call Id=" + rows[0]._6.uid + "&Contact=" + rows[0]._6.CALREF1 + "&DUE DATE=" + rows[0]._6.CALTXT01 + "&START TIME=" + rows[0]._6.CALSTARTDATE + "&STATUS=" + rows[0]._6.CALTXT07 + "&SUBJECT=" + rows[0]._6.CALDESCRIPTION
- The following fields are added to the variable (the destination is listed first, followed by the source field):
Call Id=uid Contact=CALREF1
DUE DATE=CALTXT01
START TIME=CALSTARTDATE
STATUS=CALTXT07
SUBJECT=CALDESCRIPTION
The goToURL function is executed, and all of the values stored in the externalAppUrl variable are inserted. The code used is as follows:
return "[ {\"action\":\"goToURL\", \"url\":\"" + externalAppUrl + "\"}]";
In some cases the data sent from the Data Source is sent as Row ID and time in milliseconds when the user needs the Contact name and Date/Time in a standard format. The following adjustment ot the example above shows how to do that.
<html><head><title>ExternalAppExample</title><script type="text/javascript"> var externalAppUrl; function openExternalApp(rows){ externalAppUrl = "testsales://spots/"; if(rows.length > 0){ externalAppUrl += "Call Id=" + rows[0]._6.uid + "&STATUS=" + rows[0]._6.CALTXT07 + "&SUBJECT=" + rows[0]._6.CALDESCRIPTION; var st = new Date(1000 * rows[0]._6.CALSTARTDATE); var sts = st.toLocaleString(); externalAppUrl += "&START TIME=" + sts; var dt = new Date(1000 * rows[0]._6.CALTXT01); var dts = dt.toDateString(); externalAppUrl += "&DUE DATE=" + dts; var contactid = rows[0]._6.CALREF1; var options = []; var option = {}; option.action = "select"; option.invoke = "openURL"; option.parameters = []; option.parameters[0] = { modulefields : [{ module : "2", fields : "CONTFIRSTNAME,CONTLASTNAME" }], filter : "2.uid="+contactid }; options.push(option); return JSON.stringify(options); }else{ return "[ {\"action\":\"goToURL\", \"url\":\"" + externalAppUrl + "\"}]"; } } function openURL(contacts){ if(contacts.length > 0){ externalAppUrl = "&Contact=" + contacts[0]._2.CONTFIRSTNAME " " + contacts[0]._2.CONTLASTNAME; } return "[ {\"action\":\"goToURL\", \"url\":\"" + externalAppUrl + "\"}]"; } </script></head><body></body></html>