/
editQuery.html
executable file
·191 lines (168 loc) · 6.41 KB
/
editQuery.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!doctype html>
<html>
<head>
<title> </title>
<script src="../fmxj.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../css/fmxj.css">
<script src="../libraries/prism.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../libraries/prism.css">
</head>
<body>
<div style="float:right">
<a href="http://SeedCode.com" style="cursor:pointer"><img src="../logowhite.png" alt="SeedCode Logo" style="width:290px;height:93px;display:block"></a>
</div>
<p>
<br>
</p>
<div class="title">
fmxj.js
</div>
<div class="sub-title">
a JavaScript approach to FileMaker Custom Web Publishing
</div>
<div class="sidebar" id="sb"></div>
<div class="content">
<h3 class="functionTitle">editRecordURL(fileName, layoutName, editObj)</h3>
<div class="text">Create a FileMaker -edit or -new query url from a javascript object. These queries are then passed to the <span class="func">postQueryFMS()</span> function which returns the results as a single object array.</div>
</br>
<div class="divSeparator"></div>
<div class="argument">
fileName
</div>
<span class="text">
Type:
</span>
<span class = "type string">
String
</span>
<div class="desc">
A String of the name of the hosted FileMaker file.
</div>
<div class="divSeparator"></div>
<div class="argument">
layoutName
</div>
<span class="text">
Type:
</span>
<span class = "type string">
String
</span>
<div class="desc">
A String of the name of the target layout in the specified file.
</div>
<div class="divSeparator"></div>
<div class="argument">
editObj
</div>
<span class="text">
Type:
</span>
<span class="type object">
Object
</span>
<div class="desc">An Object that specifies the changes to be made to the FileMaker record. Property names represent the FileMaker field names. Specifying a -recid property will edit the specified record with an -edit query. Not specifying the -recid will create a new FileMaker record with a -new query. The -modid property can be optionally specified to ensure you are editing the most current version of that record. See more about using the -mod id in <a href="https://fmhelp.filemaker.com/docs/13/en/fms13_cwp_xml.pdf" target="_blank">FileMaker's XML CWP Guide</a>
</div>
<div class="divSeparator"></div>
<div class="argument">example 1</div>
<div class="text">Create a new FileMaker record by not specifying the -recid in the edit object. If the record creation is succesful on the server, then the record will be returned and converted into an object.
</div>
<pre class="line-numbers">
<code class="language-javascript">
var newRecord = {
"DateStart" : "02/25/2014" ,
"DateEnd" : "02/25/2014" ,
"Description" : "test" ,
"Status" : "Open" ,
"Summary" : "test summary ubi"
} ;
var query = fmxj.editRecordURL("Events", "Events", newRecord) ;
fmxj.postQueryFMS(query, callBackFunction) ;</code></pre>
<button id="btn1">try example 1</button>
<pre id="example1" class="result tall"></pre>
<div class="divSeparator"></div>
<div class="argument">example 2</div>
<div class="text">Specifying a -recid property in an object will create a edit query to edit the fields specified in the object. Retrieve the first record on the Events layout and toggle its status. If the status is open, set it to closed and vice-versa.
</div>
<pre class="line-numbers">
<code class="language-javascript">
// query to find all records, unsorted and return the first one.
var query = fmxj.findRecordsURL("Events", "Events", null, null, 1);
fmxj.postQueryFMS(query,createEdit,null,relay); // Perform request
function createEdit(js){ //define handler for returned record
var recid = js[0]["-recid"]; //retrieve record/object's -recid
var modid = js[0]["-modid"]; //retrieve record/object's -modid
var recordStatus = js[0]["Status"]; //retrieve record/object's status
if ( recordStatus == "Open" ){ //toggle status
recordStatus = "Closed"
}
else {
recordStatus = "Open"
} ;
var editObj = { //create new object to edit the record
"-recid":recid,
"-modid":modid,
"Status":recordStatus,
};
//create query from object
var query = fmxj.editRecordURL("Events", "Events", editObj);
fmxj.postQueryFMS(query,writeResult,null,relay); //POST edit query
function writeResult(js){ //define handler for writing edited object.
updateElement("example2", message, true);
};
};</code></pre>
<button id="btn2">try example 2</button>
<pre id="example2" class="result" style="height:600px;max-height:none"></pre>
</div>
</body>
<footer>
<script src="../fmxjDemo.js" type="text/javascript"></script>
<script>
//button for editing the first object in the array
var btnedit = document.getElementById("btn2");
btnedit.addEventListener("click",function(){
start = new Date().getTime();
document.getElementById("example2").innerHTML = "" ;
// query to find all records, unsorted and return the first one.
var query = fmxj.findRecordsURL("Events", "Events", null, null, 1);
fmxj.postQueryFMS(query,createEdit,null,relay); // Perform request
function createEdit(js,utc){ //define handler for returned record
var message = "Before\n" + createDisplay(js, utc, start);
updateElement("example2", message + "\n\n");
var recid = js[0]["-recid"]; //retrieve record/object's -recid
var modid = js[0]["-modid"]; //retrieve record/object's -modid
var recordStatus = js[0]["Status"]; //retrieve record/object's status
if ( recordStatus == "Open" ){ //toggle status
recordStatus = "Closed"
}
else {
recordStatus = "Open"
} ;
var editObj = { //create object to edit the record
"-recid":recid,
"-modid":modid,
"Status":recordStatus,
};
var query = fmxj.editRecordURL("Events", "Events", editObj);
fmxj.postQueryFMS(query,writeResult,null,relay);
function writeResult(js,utc){ //define handler for writing edited object.
var message = "After\n" + createDisplay(js, utc, start);
updateElement("example2", message, true);
};
}
});
//button for new record
var btnnew = document.getElementById("btn1");
btnnew.addEventListener("click",function(){
start = new Date().getTime();
document.getElementById("example1").innerHTML = "" ;
function writeResults ( js, utc ) {
var message = createDisplay(js, utc, start);
updateElement("example1",message);
} ;
var q = fmxj.editRecordURL("Events" , "Events" , newRecord ) ;
fmxj.postQueryFMS(q,writeResults,null,relay)
});
</script>
</footer>
</html>