Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

There are two places where JavaScript code must be configured in Swift MEAP for this example external application.

 

1. Preserving the devicerowid

Typically, the application which receives the call from Swift MEAP must have the devicerowid in order to query the data source for the actual record. As a result, the devicerowid must be synchronized with the data source as well. The following procedure shows you how to update the devicerowid field and synchronize the changes with the data source.

To update the devicerowid field and synchronize the changes with the data source: 

Choose a field in the data source to set aside for storing the devicerowid of a record.  For example, use CONTTXT01 which is the field used to store the Description in the Contact module.

...

An example of the complete code with header and footer information follows. In this example, the uid and the devicerowid of the newly created Contact record are read and the IDs are passed to the UpdateCRMODDeviceRowId method, which updates the CONTXT01 field with the devicerowid. The devicerowid is synchronized with the Description field in the data source.


 

Code Block
<html><head><title>devicerowidExample</title><script type="text/javascript"

...

> 
 
function onSaveJSON() {

...

 

...


	return "[{\"action\":\"select\",\"invoke\":\"updateDSDeviceRowId\",\"parameters\":[{\" modulefields\": [ { \"module\":\"2\", \"fields\":\"uid,devicerowid\"} ],\"filter\":\"2.uid=$2.uid\"} ] } ]";

...

 


}

...


 

...


function updateDSDeviceRowId(rows) {

...

 


	var jsonscript = "[";

...

 

...


	if(rows.length > 0){

...

 

...


		jsonscript += "{\"action\":\"update\",\"module\":\"2\",\"uid\":\"" + rows[0]._2.uid + "\",\"fields\":[ { \"field\":\"CONTTXT01\", \"value\":\""+rows[0]._2.devicerowid+"\"} ], \"upsync\":\"yes\", \"filter\":\"2.uid ="+rows[0]._2.uid+"\" }";

...


 

...

	}

...


 

...

	jsonscript += "]";

...


 

...

	return jsonscript;

...

 


}

...


 

...


function onErrorInvoke(rows){

...

 


	if(rows.length > 0){

...

 


		window.location="melt://showAlert:"+ rows[0].message;

...

 

}

}

 


	}
}
</script></head><body></body></html>

...



2.  Writing the openExternalApp Function


You must write an openExternalApp function to configure a quick action button to load an external application.

To write an openExternalApp function 

  1. Start the Admin application.

  2. Click Map Settings, and then select Module Settings on the vertical application bar.

  3. Click the icon for Quick Action.

  4. Click Add in the External App Configuration section to configure a new action.

  5. Configure the fields for the external application as follows:

    1. App URL. Enter the application URL that loads the external application into the App URL input box.

    2. Display Value. Enter a display value to identify the external application. The display value is the name that will appear when the user selects the quick action button in the client application.

  6. Enter the JavaScript Object Notation (JSON) code into the input box.

  7. Create the openExternalApp function, which will contain the logic for calling out to the external application, and enter the code into the input box.

...

An example of the complete code for the openExternalApp function, with header and footer information, is as follows.


 

Code Block
<html><head><title>Example External App</title><script type="text/javascript"

...

function openExternalApp(rows) {

...

 

...


	var externalAppURL="http://localhost/Test.

...

html"; 
	externalAppURL+="?ContFrstName="+rows[0]._2.CONTFIRSTNAME; externalAppURL+="&ContLstName="+rows[0]._2.CONTLASTNAME; 		
	externalAppURL+="&PresRowId="+rows[0]._2.CONTTXT01; externalAppURL+="&Id="+rows[0]._2.uid;

...


 

...

	return "[ {\"action\":\"goToURL\",\"noescape\":\"true\",\"url\":\"" + externalAppURL + "\"} ]";

...

 

}

 


}
</script></head></html>


In this example, note the following key points:

...

  • A call out to a Web page is made. The First name, Last name, and CONTTXT01 values of the Contact are passed over to display on the Web page. The Web page has a submit button, which launches the Swift MEAP client application.

  • The externalAppURL variable holds the value of the URL, which is to be called out. Data is passed from the Contact using the query parameters in the URL.

  • Passing the record row ID, rows[0]._2.uid, helps the external application to determine which record is being viewed.

  • The goToURL action calls out to the external application URL, which opens the Safari browser and loads the requested URL.

...


Note
There is a noescape parameter in the goToURL action, which specifies whether or not to encode the URL. The noescape parameter can be set to either True or False. Do not use spaces in the URL when setting to True (noescape=true) or False (noescape=false).