-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnetSuiteDemo.ur
73 lines (62 loc) · 2.87 KB
/
netSuiteDemo.ur
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
open NetSuite
(* For this demo, it's necessary to create netSuiteSecrets.ur,
* defining [account_id], [consumer_key], [consumer_secret], [token_id], and [token_secret]. *)
structure N = NetSuite.Make(NetSuite.TwoLegged(NetSuiteSecrets))
structure C = N.Table(struct
val stable = readError "Contact"
con fields = [Firstname = string,
Email = string]
val labels = {Firstname = "firstname",
Email = "email"}
con relations = [Company = [CompanyTitle = string]]
val rlabels = {Company = ("company",
"entity",
{CompanyTitle = "entityTitle"})}
val rjsons = {Company = _}
end)
structure C' = N.Table(struct
val stable = readError "Contact"
con fields = [Firstname = string,
Email = string,
Company = string]
val labels = {Firstname = "firstname",
Email = "email",
Company = "company"}
con relations = []
val rlabels = {}
val rjsons = {}
end)
val optionify = @@mp [ident] [option] (fn [t] => Some)
fun create r =
C'.insert (NetSuite.values (optionify r));
return <xml><body>OK.</body></xml>
fun update id r =
C'.update id (NetSuite.values (optionify r));
return <xml><body>OK.</body></xml>
fun edit id =
ls <- C'.query (select [[Firstname = _, Email = _, Company = _]]
|> wher (eq (field [#Id]) (string id)));
case ls of
r :: [] => return <xml><body>
<form>
First name: <textbox{#Firstname} value={Option.get "" r.Firstname}/><br/>
Email: <textbox{#Email} value={Option.get "" r.Email}/><br/>
Company: <textbox{#Company} value={Option.get "" r.Company}/><br/>
<submit action={update id}/>
</form>
</body></xml>
| _ => error <xml>Bad query response</xml>
fun main () =
ls <- C.query (select [[Id = _, Firstname = _, Email = _]]
|> rselect [#Company] [[CompanyTitle = _]]);
return <xml><body>
<ol>
{List.mapX (fn r => <xml><li><a link={edit (Option.get "" r.Id)}>{[r.Firstname]} @ {[r.Email]} @ {[r.CompanyTitle]}</a></li></xml>) ls}
</ol>
<form>
First name: <textbox{#Firstname}/><br/>
Email: <textbox{#Email}/><br/>
Company: <textbox{#Company}/><br/>
<submit action={create}/>
</form>
</body></xml>