Skip to content

Commit

Permalink
ServiceNow: querying full table contents generically
Browse files Browse the repository at this point in the history
  • Loading branch information
achlipala committed Aug 27, 2023
1 parent 5a48dc0 commit 76bb3ec
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/serviceNowDemo.ur
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ val main =
</xml>) ts}
</table>
</body></xml>

val incidents =
is <- S.Table.list {Description = "description",
Severity = "severity"} "incident";
return <xml><body>
<table>
<tr><th>Description</th> <th>Severity</th></tr>

{List.mapX (fn {Description = d : option string,
Severity = s : option int} => <xml>
<tr><td>{[d]}</td> <td>{[s]}</td></tr>
</xml>) is}
</table>
</body></xml>
1 change: 1 addition & 0 deletions examples/serviceNowDemo.urs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
val main : transaction page
val incidents : transaction page
19 changes: 19 additions & 0 deletions src/ur/serviceNow.ur
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ functor Make(M : AUTH) = struct
cs' <- columns p.Nam;
return (List.append cs cs')
end

structure Table = struct
fun list [ts] (fl : folder ts) (labels : $(map (fn _ => string) ts))
(jsons : $(map json ts)) (tname : string) =
fields <- return (@foldR [fn _ => string] [fn _ => string]
(fn [nm ::_] [t ::_] [r ::_] [[nm] ~ r]
(label : string) (acc : string) =>
case acc of
"" => label
| _ => acc ^ "," ^ label)
"" fl labels);
s <- api ("table/" ^ Urls.urlencode tname ^ "?sysparm_fields=" ^ fields);
v <- return (@fromJson
(@json_result (@json_list
(@json_record_withOptional ! _ {} {}
fl jsons labels)))
s : result (list $(map option ts)));
return v.Result
end
end

functor ThreeLegged(M : sig
Expand Down
9 changes: 9 additions & 0 deletions src/ur/serviceNow.urs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ functor Make(M : AUTH) : sig
val list : transaction (list tabl)
val columns : string -> transaction (list column)
end

structure Table : sig
val list : ts ::: {Type}
-> folder ts
-> $(map (fn _ => string) ts) (* labels in JSON *)
-> $(map Json.json ts)
-> string (* table name *)
-> transaction (list $(map option ts))
end
end

0 comments on commit 76bb3ec

Please sign in to comment.