Wiki source code of Metadaten
Show last authors
author | version | line-number | content |
---|---|---|---|
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. | ||
3 | {{/figure}} | ||
4 | |||
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. | ||
6 | |||
7 | The object //XFC_METADATA// has got the following entries. For further details on these properties and nested properties, see the linked documentation: | ||
8 | |||
9 | * {{jsdoc page="metadata" name="attachments"/}} | ||
10 | * {{jsdoc page="metadata" name="currentClient"/}} | ||
11 | * {{jsdoc page="metadata" name="currentLanguage"/}} | ||
12 | * {{jsdoc page="metadata" name="currentLanguageTag"/}} | ||
13 | * {{jsdoc page="metadata" name="currentProcess"/}} | ||
14 | * {{jsdoc page="metadata" name="currentProject"/}} | ||
15 | * {{jsdoc page="metadata" name="currentSessionFRID"/}} | ||
16 | * {{jsdoc page="metadata" name="currentSessionID"/}} | ||
17 | * {{jsdoc page="metadata" name="pluginResults"/}} | ||
18 | * {{jsdoc page="metadata" name="renderStatus"/}} | ||
19 | * {{jsdoc page="metadata" name="requestType"/}} | ||
20 | * {{jsdoc page="metadata" name="serverTime"/}} | ||
21 | * {{jsdoc page="metadata" name="urlParams"/}} | ||
22 | * {{jsdoc page="metadata" name="urls"/}} | ||
23 | * {{jsdoc page="metadata" name="user"/}} | ||
24 | |||
25 | Outdated properties of //XFC_METADATA//: | ||
26 | |||
27 | * --XFC_METADATA.currentUser--: Replaced by {{jsdoc page="metadata" name="user"/}} | ||
28 | |||
29 | == Examples == | ||
30 | |||
31 | {{panel title="Retrieve the user name of the current user"}} | ||
32 | |||
33 | {{js}} | ||
34 | const username = XFC_METADATA.user.userName; | ||
35 | {{/js}} | ||
36 | |||
37 | {{jsIE}} | ||
38 | var username = XFC_METADATA.user.userName; | ||
39 | {{/jsIE}} | ||
40 | |||
41 | {{/panel}} | ||
42 | |||
43 | {{panel title="Retrieve LDAP data from the current user"}} | ||
44 | |||
45 | {{js}} | ||
46 | const rawData = XFC_METADATA.user.rawData; | ||
47 | {{/js}} | ||
48 | |||
49 | {{jsIE}} | ||
50 | var rawData = XFC_METADATA.user.rawData; | ||
51 | {{/jsIE}} | ||
52 | |||
53 | {{/panel}} | ||
54 | |||
55 | {{panel title="Read the value of an URL parameter named lang"}} | ||
56 | |||
57 | {{js}} | ||
58 | const foobar = XFC_METADATA.urlParams.lang; | ||
59 | {{/js}} | ||
60 | |||
61 | {{jsIE}} | ||
62 | var foobar = XFC_METADATA.urlParams.lang; | ||
63 | {{/jsIE}} | ||
64 | |||
65 | {{/panel}} | ||
66 | |||
67 | |||
68 | {{panel title="Write the server time to an input field"}} | ||
69 | {{code width="600px" language="javascript"}} | ||
70 | $("[name='tfServertime']").val(XFC_METADATA.serverTime.toString()); | ||
71 | {{/code}} | ||
72 | {{/panel}} | ||
73 | |||
74 | |||
75 | {{panel width="600px" title="Prefill an email input field with the data of current user"}} | ||
76 | |||
77 | {{js}} | ||
78 | $.xutil.onStatus(() => $('[name="tfMail"]').val(XFC_METADATA.user.mail)); | ||
79 | {{/js}} | ||
80 | |||
81 | {{jsIE}} | ||
82 | $.xutil.onStatus(function() { | ||
83 | $('[name="tfMail"]').val(XFC_METADATA.user.mail); | ||
84 | }); | ||
85 | {{/jsIE}} | ||
86 | |||
87 | {{/panel}} | ||
88 | |||
89 | |||
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 | |||
93 | {{js}} | ||
94 | // Build the URL for a form file | ||
95 | function getResourceURL(filename){ | ||
96 | // Read the ID of the current form | ||
97 | const pid = String(window.XFC_METADATA.currentProject.id); | ||
98 | // Take the beginning part of the URL from the metadata object | ||
99 | const url = `${XFC_METADATA.urls.context}includes/ressource?pid=${pid}&name=${encodeURIComponent(filename)}`; | ||
100 | return url; | ||
101 | } | ||
102 | // We uploaded the file "myData.json" as a form file | ||
103 | $.get(getResourceURL("myData.json")).then(data => { | ||
104 | // Do something with the data from the file "myData.json" | ||
105 | }); | ||
106 | {{/js}} | ||
107 | |||
108 | {{jsIE}} | ||
109 | // Build the URL for a form file | ||
110 | function getResourceURL(filename){ | ||
111 | // Read the ID of the current form | ||
112 | var pid = String(window.XFC_METADATA.currentProject.id); | ||
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}; | ||
115 | return url; | ||
116 | } | ||
117 | // We uploaded the file "myData.json" as a form file | ||
118 | $.get(getResourceURL("myData.json"), undefined, function(data) { | ||
119 | // Do something with the data from the file "myData.json" | ||
120 | }); | ||
121 | {{/jsIE}} | ||
122 | |||
123 | {{/panel}} | ||
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}} |