Metadata
The global object window.XFC_METADATA contains meta data related to the currently opened form; such as the state of the form, the user that is currently signed in, the the form record and much more. When you open a form, this object is added automatically and filled with the relevant information.
The object XFC_METADATA has got the following entries. For further details on these properties and nested properties, see the linked documentation:
- XFC_METADATA.attachments
- XFC_METADATA.currentClient
- XFC_METADATA.currentLanguage
- XFC_METADATA.currentLanguageTag
- XFC_METADATA.currentProcess
- XFC_METADATA.currentProject
- XFC_METADATA.currentSessionFRID
- XFC_METADATA.currentSessionID
- XFC_METADATA.pluginResults
- XFC_METADATA.renderStatus 6.2.0+
- XFC_METADATA.requestType
- XFC_METADATA.serverTime
- XFC_METADATA.urlParams
- XFC_METADATA.urls
- XFC_METADATA.user 6.4.0+
Outdated properties of XFC_METADATA:
XFC_METADATA.currentUser: Replaced by XFC_METADATA.user
Examples
Retrieve the user name of the current user
const username = XFC_METADATA.user.userName;
var username = XFC_METADATA.user.userName;
Retrieve LDAP data from the current user
const rawData = XFC_METADATA.user.rawData;
var rawData = XFC_METADATA.user.rawData;
Read the value of an URL parameter named lang
const foobar = XFC_METADATA.urlParams.lang;
var foobar = XFC_METADATA.urlParams.lang;
Write the server time to an input field
$("[name='tfServertime']").val(XFC_METADATA.serverTime.toString());
Prefill an email input field with the data of current user
$.xutil.onStatus(() => $('[name="tfMail"]').val(XFC_METADATA.user.mail));
$.xutil.onStatus(function() {
$('[name="tfMail"]').val(XFC_METADATA.user.mail);
});
$('[name="tfMail"]').val(XFC_METADATA.user.mail);
});
Access a form-specific resource
When there is a file named myData.json uploaded as form-specific resource, you can access it as follows:
// Build the URL for a form file
function getResourceURL(filename){
// Read the ID of the current form
const pid = String(window.XFC_METADATA.currentProject.id);
// Take the beginning part of the URL from the metadata object
const url = `${XFC_METADATA.urls.context}includes/ressource?pid=${pid}&name=${encodeURIComponent(filename)}`;
return url;
}
// We uploaded the file "myData.json" as a form file
$.get(getResourceURL("myData.json")).then(data => {
// Do something with the data from the file "myData.json"
});
function getResourceURL(filename){
// Read the ID of the current form
const pid = String(window.XFC_METADATA.currentProject.id);
// Take the beginning part of the URL from the metadata object
const url = `${XFC_METADATA.urls.context}includes/ressource?pid=${pid}&name=${encodeURIComponent(filename)}`;
return url;
}
// We uploaded the file "myData.json" as a form file
$.get(getResourceURL("myData.json")).then(data => {
// Do something with the data from the file "myData.json"
});
// Build the URL for a form file
function getResourceURL(filename){
// Read the ID of the current form
var pid = String(window.XFC_METADATA.currentProject.id);
// Take the beginning part of the URL from the metadata object
var url = XFC_METADATA.urls.context + "includes/ressource?pid=" + pid + "&name=" + encodeURIComponent(filename};
return url;
}
// We uploaded the file "myData.json" as a form file
$.get(getResourceURL("myData.json"), undefined, function(data) {
// Do something with the data from the file "myData.json"
});
function getResourceURL(filename){
// Read the ID of the current form
var pid = String(window.XFC_METADATA.currentProject.id);
// Take the beginning part of the URL from the metadata object
var url = XFC_METADATA.urls.context + "includes/ressource?pid=" + pid + "&name=" + encodeURIComponent(filename};
return url;
}
// We uploaded the file "myData.json" as a form file
$.get(getResourceURL("myData.json"), undefined, function(data) {
// Do something with the data from the file "myData.json"
});
Examples for older FORMCYCLE versions
Retrieve the user name of the current user in FORMCYCLE before version 6.4.0
const username = XFC_METADATA.currentUser.username;
var username = XFC_METADATA.currentUser.username;
Retrieve LDAP data from the current user in FORMCYCLE before version 6.4.0
const ldapData = XFC_METADATA.currentUser.ldap;
var ldapData = XFC_METADATA.currentUser.ldap;