Hide last authors
nlo 21.1 1 {{figure image="designer_advanced_xfc_metadata_en.png" width="700"}}
2 You can use the global JavaScript object {{code language="javascript"}}window.XFC_METADATA{{/code}} to get access to a variety of information relating to the current form. Here we prefill an input field for an email adress with the email of the user who is currently signed in. We do this only if the form was opened freshly and not submitted yet. Also, as shown in the figure above, the autocomplete feature works even for nested properties.
gru 1.1 3 {{/figure}}
4
nlo 21.1 5 The global object {{code language="javascript"}}window.XFC_METADATA{{/code}} 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.
gru 1.1 6
nlo 21.1 7 The object //XFC_METADATA// has got the following entries. For further details on these properties and nested properties, see the linked documentation:
gru 1.1 8
awa 7.5 9 * {{jsdoc page="metadata" name="attachments"/}}
awa 11.8 10 * {{jsdoc page="metadata" name="currentClient"/}}
awa 11.9 11 * {{jsdoc page="metadata" name="currentLanguage"/}}
12 * {{jsdoc page="metadata" name="currentLanguageTag"/}}
13 * {{jsdoc page="metadata" name="currentProcess"/}}
14 * {{jsdoc page="metadata" name="currentProject"/}}
awa 11.10 15 * {{jsdoc page="metadata" name="currentSessionFRID"/}}
16 * {{jsdoc page="metadata" name="currentSessionID"/}}
awa 11.9 17 * {{jsdoc page="metadata" name="pluginResults"/}}
awa 11.11 18 * {{jsdoc page="metadata" name="renderStatus"/}} {{version major="6" minor="2"/}}
awa 11.9 19 * {{jsdoc page="metadata" name="requestType"/}}
20 * {{jsdoc page="metadata" name="serverTime"/}}
21 * {{jsdoc page="metadata" name="urlParams"/}}
awa 7.5 22 * {{jsdoc page="metadata" name="urls"/}}
nlo 12.1 23 * {{jsdoc page="metadata" name="user"/}} {{version major="6" minor="4"/}}
gru 1.1 24
nlo 21.1 25 Outdated properties of //XFC_METADATA//:
nlo 13.1 26
nlo 21.1 27 * --XFC_METADATA.currentUser--: Replaced by {{jsdoc page="metadata" name="user"/}}
nlo 13.1 28
nlo 21.1 29 == Examples ==
gru 1.1 30
nlo 21.1 31 {{panel title="Retrieve the user name of the current user"}}
awa 11.6 32
33 {{js}}
nlo 21.1 34 const username = XFC_METADATA.user.userName;
awa 11.6 35 {{/js}}
36
37 {{jsIE}}
nlo 21.1 38 var username = XFC_METADATA.user.userName;
awa 11.6 39 {{/jsIE}}
gru 1.1 40
awa 11.6 41 {{/panel}}
gru 1.1 42
nlo 21.1 43 {{panel title="Retrieve LDAP data from the current user"}}
awa 11.6 44
nlo 16.1 45 {{js}}
nlo 15.1 46 const rawData = XFC_METADATA.user.rawData;
awa 11.6 47 {{/js}}
48
49 {{jsIE}}
nlo 15.1 50 var rawData = XFC_METADATA.user.rawData;
awa 11.6 51 {{/jsIE}}
52
gru 1.1 53 {{/panel}}
54
nlo 21.1 55 {{panel title="Read the value of an URL parameter named lang"}}
gru 1.1 56
nlo 19.1 57 {{js}}
nlo 21.1 58 const foobar = XFC_METADATA.urlParams.lang;
nlo 19.1 59 {{/js}}
60
61 {{jsIE}}
nlo 21.1 62 var foobar = XFC_METADATA.urlParams.lang;
nlo 19.1 63 {{/jsIE}}
64
65 {{/panel}}
66
67
nlo 21.1 68 {{panel title="Write the server time to an input field"}}
69 {{code width="600px" language="javascript"}}
awa 10.5 70 $("[name='tfServertime']").val(XFC_METADATA.serverTime.toString());
gru 1.1 71 {{/code}}
72 {{/panel}}
73
74
nlo 21.1 75 {{panel width="600px" title="Prefill an email input field with the data of current user"}}
awa 11.7 76
77 {{js}}
nlo 20.1 78 $.xutil.onStatus(() => $('[name="tfMail"]').val(XFC_METADATA.user.mail));
awa 11.7 79 {{/js}}
80
81 {{jsIE}}
82 $.xutil.onStatus(function() {
nlo 20.1 83 $('[name="tfMail"]').val(XFC_METADATA.user.mail);
awa 11.7 84 });
85 {{/jsIE}}
86
awa 7.3 87 {{/panel}}
awa 10.4 88
awa 11.7 89
nlo 21.1 90 {{panel title="Access a form-specific resource"}}
91 (((When there is a file named //myData.json// uploaded as form-specific resource, you can access it as follows:)))
92
awa 11.7 93 {{js}}
nlo 21.1 94 // Build the URL for a form file
95 function getResourceURL(filename){
96 // Read the ID of the current form
awa 10.4 97 const pid = String(window.XFC_METADATA.currentProject.id);
nlo 21.1 98 // Take the beginning part of the URL from the metadata object
awa 10.4 99 const url = `${XFC_METADATA.urls.context}includes/ressource?pid=${pid}&name=${encodeURIComponent(filename)}`;
100 return url;
101 }
nlo 21.1 102 // We uploaded the file "myData.json" as a form file
awa 10.4 103 $.get(getResourceURL("myData.json")).then(data => {
nlo 21.1 104 // Do something with the data from the file "myData.json"
awa 10.4 105 });
awa 11.7 106 {{/js}}
107
108 {{jsIE}}
nlo 21.1 109 // Build the URL for a form file
110 function getResourceURL(filename){
111 // Read the ID of the current form
awa 11.7 112 var pid = String(window.XFC_METADATA.currentProject.id);
nlo 21.1 113 // Take the beginning part of the URL from the metadata object
114 var url = XFC_METADATA.urls.context + "includes/ressource?pid=" + pid + "&name=" + encodeURIComponent(filename};
awa 11.7 115 return url;
116 }
nlo 21.1 117 // We uploaded the file "myData.json" as a form file
awa 11.7 118 $.get(getResourceURL("myData.json"), undefined, function(data) {
nlo 21.1 119 // Do something with the data from the file "myData.json"
awa 11.7 120 });
121 {{/jsIE}}
122
awa 10.4 123 {{/panel}}
nlo 21.1 124
125 == Examples for older FORMCYCLE versions ==
126
127 {{panel title="Retrieve the user name of the current user in FORMCYCLE before version 6.4.0"}}
128
129 {{js}}
130 const username = XFC_METADATA.currentUser.username;
131 {{/js}}
132
133 {{jsIE}}
134 var username = XFC_METADATA.currentUser.username;
135 {{/jsIE}}
136
137 {{/panel}}
138
139 {{panel title="Retrieve LDAP data from the current user in FORMCYCLE before version 6.4.0"}}
140
141 {{js}}
142 const ldapData = XFC_METADATA.currentUser.ldap;
143 {{/js}}
144
145 {{jsIE}}
146 var ldapData = XFC_METADATA.currentUser.ldap;
147 {{/jsIE}}
148
149 {{/panel}}
Copyright 2000-2024