About Custom Forms
While performing an activity, if you want to perform additional activities, you can use custom forms. They contain an external URL with the required information. They are created in Plant Applications Administrator.
- Configure the URL of the custom form.
- Configure the Autolog sheets to generate custom form driven activities.
- Configure the user name and password for the user authentication of the custom form.
Data Flow
- The user performs a custom activity in the Activities application.
- The Activities application initiates the Handshake protocol by sending a message to the form and checks whether the URL of the custom form is valid.
- If the URL is valid, the Activities application receives the message back. The application then adds an event listener to hear from the origin and then posts the message with the variable data to the custom form.
- If the URL is not valid, an error message appears in the Activities application.
Post Data
window.postmessage()
method is used to send data from the Activities application to the custom form. The window.postmessage()
method enables cross-origin communication between the following items: - Window objects such as between a page and a window that the page spawned.
Example: The
window.postmessage()
method is used when you select the option to access the URL of the custom in a separate page. - A page and iframe such as between a page and an iframe embedded within the page.
Example: The
window.postmessage()
method is used when you select the option to access the URL of the custom form embedded within the window displaying the autolog sheet or as a replacement of the window displaying the autolog sheet.
window.postMessage()
method are exposed to the receiving window through the event object. The Activities application creates an instance of target window to post message by using the following syntax: targetWindow.postmessage(message, targetOrigin, [transfer]);
targetWindow
is a reference of the custom form window that receives the message.message
is data to be sent to the custom form. The data is serialized using the structured clone algorithm. The algorithm enables you to pass a broad variety of data objects safely to the destination window without serializing them.targetOrigin
is the origin of target window. By default, asterisk (*) is set to indicate no preference. ThepostMessage()
transmits vital information. It is absolutely critical that this argument be a URI whose origin is the same as the intended receiver of the message containing the password to prevent interception of the password by a malicious third party.Transfer
is a sequence of transferable objects that are transferred with the message. An optional parameter not used in the Activities application.
Event Listener
window.addEventListener(“message”, receiveMessage, false);
function receiveMessage(event)
{
if (event.origin !== "http://example.org:8080")
return;
}
The properties of the dispatched message are: data (event.data)
: The information passed by the Activities application.origin
: The origin of the window that sent the message at the timepostMessage
was called. In the code snippet, thehttp://example.org:8080
is an example oforigin
.source
: A reference to the window object that sent the message. You can use this property to establish two-way communication between two windows with different origins.
Security Concerns
- If you do not expect to receive messages from other sites, disable the Activities application to add any event listeners for message events.
- If you expect to receive messages from other sites, always verify the sender's identity using the
origin
and possibly source properties. Any window (including a URL) can send a message to any other window, and an unknown sender can send malicious messages. You must verify the syntax of the received message.Note: Failure to check theorigin
and possiblysource
properties enables cross-site scripting attacks. - Always specify an exact target origin, not an asterisk (*) in the Activities application configuration when you use
postMessage
to send data to other windows. A malicious site can change the location of the window without your knowledge. Therefore, the site can intercept the data sent usingpostMessage
.
Data Sent to a Custom Form
The data sent to custom form in the event.Data
object is in the JSON format. The following code sample shows the data sent to a custom form and the syntax to access the data.
{
"loggedUserInfo": {
"token": <<token>>
},
"header": {
"activityId": <<activityId>>,
"activityType": <<activityType>>,
"activityDescription": <<activityName>>,
"startTime": <<startTime>>
},
"productInfo": <<productId>>,
"processOrderInfo": <<processOrder>>,
"variableInfo": <<variable_data>>,
"activityStatusInfo": {
"statusId": <<Activity_statusId>>,
"status": <<Activity_status>>,
"readOnly": <<readOnly_status>>
},
"userConfigurationDetails": <<customActivityUser>>
}
loggedUserInfo
: Provides the user name and token. The UAA token is required when the custom forms use the public REST APIs provided to save variables into SOADB.Header
: Provides the activity ID, activity type as Production, Time-Based, or User-Defined, activity description, and start time of the activity.ProductInfo
: Provides the ID, name, and value of the product.ProcessOrderInfo
: Provides the ID, name, and value of the process order.Variables
: Provides the list of variables with ID, name, data type, and value.ActivityStatusInfo
: Provides information regarding whether the activity is locked, read-only state, or modifiable.userConfigurationDetails
: Provides the user name and password configured in Plant Applications.
Data Size
As a data point, the WebKit implementation (used by Safari and Chrome) does not currently enforce any limits regarding the size of the data sent through a message.
- Same domain: successful (same IP address)
- Cross domain: successful (with different IP addresses and ports, messages transfer between http and https)
- Data cannot be transmitted using form headers, form body, or query parameters by using
postmessage
. - All data is transmitted through
postmessage
only.