-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sdk.FetchXml.ts
3117 lines (2891 loc) · 119 KB
/
Sdk.FetchXml.ts
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
The MIT License (MIT)
Copyright (c) 2016 Jim Daly
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
namespace Sdk.FetchXml {
@sealed
export class attribute {
/**
* Contains the data for a fetchXml attribute element.
* @param name The logical name of the attribute
*/
constructor(name: string) {
//new keyword not required
if (!(this instanceof attribute))
{ return new attribute(name) }
this.name = name;
}
private _name: string;
private _build: Build = null;
private _addedBy: string = null;
private _alias: string = null;
private _aggregate: Aggregate = null;
private _groupBy: boolean = null;
private _dateGrouping: DateGrouping = null;
private _userTimeZone: boolean = null;
/**
*Gets or sets logical name of the attribute
*/
public get name(): string {
return this._name;
}
public set name(value: string) {
if (!Util.isString(value)) {
throw new Error("Sdk.FetchXml.attribute name property must be an string.");
}
this._name = value;
}
/**
*Gets or sets the build of the attribute
*/
public get build(): Build {
return this._build;
}
public set build(value: Build) {
if (!Util.isEnumMemberOrNull(Build, value)) {
throw new Error("Sdk.FetchXml.attribute build property must be an Sdk.FetchXml.Build value or null.");
}
this._build = value;
}
/**
*Gets or sets the addedBy property of the attribute
*/
public get addedBy(): string {
return this._addedBy;
}
public set addedBy(value: string) {
if (!Util.isStringOrNull(value)) {
throw new Error("Sdk.FetchXml.attribute addedBy property must be an string value or null.");
}
this._addedBy = value;
}
/**
*Gets or sets the alias property of the attribute
*/
public get alias(): string {
return this._alias;
}
public set alias(value: string) {
if (!Util.isStringOrNull(value)) {
throw new Error("Sdk.FetchXml.attribute alias property must be an string value or null.");
}
this._alias = value;
}
/**
*Gets or sets the aggregate property of the attribute
*/
public get aggregate(): Aggregate {
return this._aggregate;
}
public set aggregate(value: Aggregate) {
if (!Util.isEnumMemberOrNull(Aggregate, value)) {
throw new Error("Sdk.FetchXml.attribute aggregate property must be an Sdk.FetchXml.Aggregate value or null.");
}
this._aggregate = value;
}
/**
*Gets or sets the groupBy property of the attribute
*/
public get groupBy(): boolean {
return this._groupBy;
}
public set groupBy(value: boolean) {
if (!Util.isBooleanOrNull(value)) {
throw new Error("Sdk.FetchXml.attribute groupBy property must be an boolean value or null.");
}
this._groupBy = value;
}
/**
* Gets or sets the dateGrouping property of the attribute
*/
public get dateGrouping(): DateGrouping {
return this._dateGrouping;
}
public set dateGrouping(value: DateGrouping) {
if (!Util.isEnumMemberOrNull(DateGrouping, value)) {
throw new Error("Sdk.FetchXml.attribute dateGrouping property must be an Sdk.FetchXml.DateGrouping value or null.");
}
this._dateGrouping = value;
}
/**
*Gets or sets the userTimeZone property of the attribute
*/
public get userTimeZone(): boolean {
return this._userTimeZone;
}
public set userTimeZone(value: boolean) {
if (!Util.isBooleanOrNull(value)) {
throw new Error("Sdk.FetchXml.attribute userTimeZone property must be an boolean value or null.");
}
this._userTimeZone = value;
}
/** @description Sets the name property of the attribute attribute
* @param {string} name The name value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setName(name: string) {
this.name = name;
return this;
}
/** @description Sets the build property of the build attribute
* @param {Sdk.FetchXml.Build | null} build The build value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setBuild(build?: Build) {
(build) ? this.build = build : this.build = null;
return this;
}
/** @description Sets the addedBy property of the attribute attribute
* @param {string | null} addedBy The addedBy value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setAddedBy(addedBy?: string) {
(addedBy) ? this.addedBy = addedBy : this.addedBy = null;
return this;
}
/** @description Sets the alias property of the attribute attribute
* @param {string} alias The alias value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setAlias(alias?: string) {
(alias) ? this.alias = alias : this.alias = null;
return this;
}
/** @description Sets the aggregate property of the attribute attribute
* @param {Sdk.FetchXml.Aggregate | null } aggregate The aggregate value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setAggregate(aggregate?: Aggregate) {
(aggregate) ? this.aggregate = aggregate : this.aggregate = null;
return this;
}
/** @description Sets the groupBy property of the attribute attribute
* @param {boolean | null} groupBy The groupBy value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setGroupBy(groupBy?: boolean) {
(groupBy) ? this.groupBy = groupBy : groupBy = null;
return this;
}
/** @description Sets the dateGrouping property of the attribute attribute
* @param {Sdk.FetchXml.DateGrouping | null} dateGrouping The dateGrouping value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setDateGrouping(dateGrouping?: DateGrouping) {
(dateGrouping) ? this.dateGrouping = dateGrouping : this.dateGrouping = null;
return this;
}
/** @description Sets the userTimeZone property of the attribute attribute
* @param {boolean | null} userTimeZone The userTimeZone value to apply to the attribute
* @returns {Sdk.FetchXml.attribute}
*/
public setUserTimeZone(userTimeZone?: boolean) {
(userTimeZone) ? this.userTimeZone = userTimeZone : this.userTimeZone = null;
return this;
}
//Internal use only
toXml(doc: XMLDocument): Node {
var aNode = doc.createElement("attribute");
aNode.setAttribute("name", <string>this.name);
if (this.build) {
aNode.setAttribute("build", <string>this.build);
}
if (this.addedBy) {
aNode.setAttribute("addedby", <string>this.addedBy);
}
if (this.alias) {
aNode.setAttribute("alias", <string>this.alias);
}
if (this.aggregate) {
aNode.setAttribute("aggregate", <string>this.aggregate);
}
if (Util.isBoolean(this.groupBy)) {
aNode.setAttribute("groupby", (this.groupBy) ? "true" : "false");
}
if (this.dateGrouping) {
aNode.setAttribute("dategrouping", <string>this.dateGrouping);
}
if (Util.isBoolean(this.userTimeZone)) {
aNode.setAttribute("usertimezone", (this.userTimeZone) ? "true" : "false");
}
return aNode;
}
//Internal use only
static attributeFromXml(xml) {
var attObj = new attribute(xml.attributes.getNamedItem("name").nodeValue);
Util.parseAttributes(xml, attObj, (attObj, name, value) => {
switch (name) {
case "build":
case "alias":
case "aggregate":
attObj[name] = value;
break;
case "addedby":
attObj.addedBy = value;
break;
case "dategrouping":
attObj.dateGrouping = value;
break;
case "groupby":
attObj.groupBy = Util.convertFetchBoolType(value);
case "usertimezone":
attObj.userTimeZone = Util.convertFetchBoolType(value);
break;
default:
break;
}
})
return attObj;
}
}
@sealed
export class condition {
/**
* Contains the data for a fetchXml condition element.
* @param attribute The attribute to evaluate in the condition
* @param operator The operator to use when evaluating the attribute
* @param [values] The value(s) to apply in the comparison.
*/
constructor(attribute: string, operator: Sdk.FetchXml.Operator, values?: Array<Sdk.FetchXml.value>) {
//New keyword not required in JS
if (!(this instanceof Sdk.FetchXml.condition))
{ return new Sdk.FetchXml.condition(attribute, operator, values) }
if (attribute && operator) {
this.attribute = attribute;
this.operator = operator;
}
else {
throw new Error("Sdk.FetchXml.condition constructor parameters attribute and operator are required.")
}
if (values)
this.values = values;
}
private _aggregate: Sdk.FetchXml.Aggregate = null;
private _alias: string = null;
private _attribute: string = null;
private _column: string = null;
private _entityname: string = null;
private _operator: Sdk.FetchXml.Operator = null;
private _rowAggregate: Sdk.FetchXml.RowAggregate = null;
private _uihidden: boolean = null;
private _uiname: string = null;
private _uitype: string = null;
private _values: Array<Sdk.FetchXml.value> = [];
/**
* Gets or sets the aggregate value to apply to the condition.
*/
public get aggregate(): Sdk.FetchXml.Aggregate {
return this._aggregate;
}
public set aggregate(value: Sdk.FetchXml.Aggregate) {
this._aggregate = value;
}
/**
* Gets or sets the alias value to apply to the condition.
*/
public get alias(): string {
return this._alias;
}
public set alias(value: string) {
this._alias = value;
}
/**
* Gets or sets the attribute value to apply to the condition.
*/
public get attribute(): string {
return this._attribute;
}
public set attribute(value: string) {
this._attribute = value;
}
/**
* Gets or sets the column attribute value to apply to the condition.
*/
public get column(): string {
return this._column;
}
public set column(value: string) {
this._column = value;
}
/**
* Gets or sets the entityname attribute value to apply to the condition.
*/
public get entityname(): string {
return this._entityname;
}
public set entityname(value: string) {
this._entityname = value;
}
/**
* Gets or sets the operator attribute value to apply to the condition.
*/
public get operator(): Sdk.FetchXml.Operator {
return this._operator;
}
public set operator(value: Sdk.FetchXml.Operator) {
this._operator = value;
}
/**
* Gets or sets the rowAggregate attribute value to apply to the condition.
*/
public get rowAggregate(): Sdk.FetchXml.RowAggregate {
return this._rowAggregate;
}
public set rowAggregate(value: Sdk.FetchXml.RowAggregate) {
this._rowAggregate = value;
}
/**
* Gets or sets the uihidden attribute value to apply to the condition.
*/
public get uihidden(): boolean {
return this._uihidden;
}
public set uihidden(value: boolean) {
this._uihidden = value;
}
/**
* Gets or sets the uiname attribute value to apply to the condition.
*/
public get uiname(): string {
return this._uiname;
}
public set uiname(value: string) {
this._uiname = value;
}
/**
* Gets or sets the uitype attribute value to apply to the condition.
*/
public get uitype(): string {
return this._uitype;
}
public set uitype(value: string) {
this._uitype = value;
}
/**
* Gets or sets the array of values to be applied to the query results
*/
public get values(): Array<Sdk.FetchXml.value> {
return this._values;
}
public set values(value: Array<Sdk.FetchXml.value>) {
if (!Sdk.FetchXml.Util.isValueArrayOrNull(value)) {
throw new Error("Sdk.FetchXml.condition.values must be an array of Sdk.FetchXml.value or null.")
}
if (value == null) {
this._values = [];
} else {
this._values = value;
}
}
//Internal use only
public get hash(): string {
var s = this._attribute.concat(<string>this._operator,
(this._aggregate ? <string>this._aggregate : ""),
(this._alias ? this._alias : ""),
(this._column ? this._column : ""),
(this._entityname ? this._entityname : ""),
(this._rowAggregate ? <string>this._rowAggregate : ""),
(Sdk.FetchXml.Util.isNullOrUndefined(this._uihidden) ? "" : this._uihidden.toString()),
(this._uiname ? this._uiname : ""),
(this._uitype ? this._uitype : ""),
Sdk.FetchXml.Util.getCollectionHash(this._values)
);
return s.hashCode();
}
/** @description Sets the value of the condition attribute
* @param {string} attribute The attribute to evaluate in the condition.
* @returns {Sdk.FetchXml.condition}
*/
public setAttribute(attributeName) {
this.attribute = attributeName;
return this;
}
/** @description Sets the value of the condition attribute
* @param {Sdk.FetchXml.Operator} operator The operator to use when evaluating the attribute.
* @returns {Sdk.FetchXml.condition}
*/
public setOperator(operator) {
this.operator = operator;
return this;
}
/** @description Sets the value of the condition operator
* @param {Array} values The the value(s) to apply in the comparison.
* @returns {Sdk.FetchXml.condition}
*/
public setValues(values) {
this.values = values;
return this;
}
/** @description Adds a value to the values to apply in the comparison
* @param {Sdk.FetchXml.value | any} value The the value to add to the values.
* @returns {Sdk.FetchXml.condition}
*/
public addValue(value) {
if (Sdk.FetchXml.Util.isValue(value)) {
this.values.push(value);
}
else {
this.values.push(new Sdk.FetchXml.value(value));
}
return this;
}
/** @description Removes any values from the values collection by reference
* @param {Sdk.FetchXml.value} value The value to remove from the values collection
* @returns {Sdk.FetchXml.condition}
*/
public removeValueByRef(value) {
if (!Sdk.FetchXml.Util.isValue(value)) {
throw new Error("Sdk.FetchXml.condition removeValueByRef method value parameter must be an Sdk.FetchXml.value.")
}
Sdk.FetchXml.Util.removeCollectionValueByRef(this.values, value);
return this;
}
/** @description Removes all matching values from the values collection
* @param {Sdk.FetchXml.value} value The value to remove from the values collection
* @returns {Sdk.FetchXml.condition}
*/
public removeValue(value) {
if (!Sdk.FetchXml.Util.isValue(value)) {
throw new Error("Sdk.FetchXml.condition removeValue method value parameter must be an Sdk.FetchXml.value.")
}
Sdk.FetchXml.Util.removeCollectionValue(this.values, value);
return this;
}
/** @description Removes all any values from the values collection with the specified value property
* @param {object} value The value to remove from the values collection
* @returns {Sdk.FetchXml.condition}
*/
public removeValueByValue(value) {
Sdk.FetchXml.Util.removeCollectionValueByProperty(this.values, "value", value);
return this;
}
/** @description Sets the Aggregate to apply in the condition
* @param {Sdk.FetchXml.Aggregate} aggregate The Aggregate to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setAggregate(aggregate) {
this.aggregate = aggregate;
return this;
}
/** @description Sets the Alias to apply in the condition
* @param {string} alias The alias to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setAlias(alias) {
this.alias = alias;
return this;
}
/** @description Sets the Column to apply in the condition
* @param {string} column The column to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setColumn(column) {
this.column = column;
return this;
}
/** @description Sets the entityname to apply in the condition
* @param {string} entityname The entityname to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setEntityname(entityname) {
this.entityname = entityname;
return this;
}
/** @description Sets the rowAggregate to apply in the condition
* @param {Sdk.FetchXml.RowAggregate} rowAggregate The rowAggregate to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setRowAggregate(rowAggregate) {
this.rowAggregate = rowAggregate;
return this;
}
/** @description Sets the uihidden to apply in the condition
* @param {boolean | null} uihidden The uihidden to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setUIhidden(uihidden) {
this.uihidden = uihidden;
return this;
}
/** @description Sets the uiname to apply in the condition
* @param {string} uihidden The uiname to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setUIname(uiname) {
this.uiname = uiname;
return this;
}
/** @description Sets the uitype to apply in the condition
* @param {string} uitype The uitype to apply in the condition
* @returns {Sdk.FetchXml.condition}
*/
public setUItype(uitype) {
this.uitype = uitype;
return this;
}
//Internal use only
toXml(doc: XMLDocument): Node {
var cNode = doc.createElement("condition");
if (this.aggregate) {
cNode.setAttribute("aggregate", <string>this.aggregate)
}
if (this.alias) {
cNode.setAttribute("alias", this.alias)
}
if (this.attribute) {
cNode.setAttribute("attribute", this.attribute)
}
if (this.column) {
cNode.setAttribute("column", this.column)
}
if (this.entityname) {
cNode.setAttribute("entityname", this.entityname)
}
if (this.operator) {
cNode.setAttribute("operator", <string>this.operator)
}
if (this.rowAggregate) {
cNode.setAttribute("rowAggregate", <string>this.rowAggregate)
}
if (Sdk.FetchXml.Util.isBoolean(this.uihidden)) {
cNode.setAttribute("uihidden", this.uihidden.toString())
}
if (this.uiname) {
cNode.setAttribute("uiname", this.uiname)
}
if (this.uitype) {
cNode.setAttribute("uitype", this.uitype)
}
/*
Note from fetch.xsd:
The attribute "value" is used for all operators that compare to a single value (for example, eq).
The element "value" is used for operators that compare to multiple values (for example, in).
Some operators require neither the attribute "value" or the element "value" (for example, null).
Groupings below are guesses and not confirmed.
*/
switch (this.operator) {
//Operators used for single values
case "begins-with":
case "ends-with":
case "eq":
case "ge":
case "gt":
case "last-x-days":
case "last-x-fiscal-periods":
case "last-x-fiscal-years":
case "last-x-hours":
case "last-x-months":
case "last-x-weeks":
case "last-x-years":
case "last-year":
case "le":
case "like":
case "lt":
case "ne":
case "neq": //Is this the same as 'ne'?
case "next-x-days":
case "next-x-fiscal-periods":
case "next-x-fiscal-years":
case "next-x-hours":
case "next-x-months":
case "next-x-weeks":
case "next-x-years":
case "not-begin-with":
case "not-end-with":
case "not-like":
case "olderthan-x-days":
case "olderthan-x-hours":
case "olderthan-x-minutes":
case "olderthan-x-months":
case "olderthan-x-weeks":
case "olderthan-x-years":
case "on":
case "on-or-after":
case "on-or-before":
case "in-fiscal-period":
case "in-fiscal-year":
if (this.values.length == 1) {
cNode.setAttribute("value", this.values[0].value)
}
else {
var enumPropertyName = Sdk.FetchXml.Util.getEnumNameFromValue(Sdk.FetchXml.Operator, this.operator);
throw new Error("Sdk.FetchXml.condition values property must contain single value when the Sdk.FetchXml.Operator." + enumPropertyName + " operator is used.");
}
break;
//Operators used for multiple values
case "between":
case "in":
case "not-between":
case "not-in":
case "in-fiscal-period-and-year":
case "in-or-after-fiscal-period-and-year":
case "in-or-before-fiscal-period-and-year":
if (this.values.length > 1) {
this.values.forEach(function (v) {
cNode.appendChild(v.toXml(doc));
})
}
else {
var enumPropertyName = Sdk.FetchXml.Util.getEnumNameFromValue(Sdk.FetchXml.Operator, this.operator);
throw new Error("Sdk.FetchXml.condition values property must contain multiple values when the Sdk.FetchXml.Operator." + enumPropertyName + " operator is used.");
}
break;
//Operators that require no values
case "above":
case "eq-businessid":
case "eq-or-above":
case "eq-or-under":
case "eq-userid": //?
case "eq-userlanguage": //?
case "eq-useroruserhierarchy":
case "eq-useroruserhierarchyandteams":
case "eq-useroruserteams":
case "eq-userteams":
case "last-fiscal-period":
case "last-fiscal-year":
case "last-month":
case "last-seven-days":
case "last-week":
case "ne-businessid"://?
case "ne-userid"://?
case "next-fiscal-period":
case "next-fiscal-year":
case "next-month":
case "next-seven-days":
case "next-week":
case "next-year":
case "not-null":
case "not-under":
case "null":
case "this-fiscal-period":
case "this-fiscal-year":
case "this-month":
case "this-week":
case "this-year":
case "today":
case "tomorrow":
case "under":
case "yesterday":
//No value required
if (this.values.length > 0) {
var enumPropertyName = Sdk.FetchXml.Util.getEnumNameFromValue(Sdk.FetchXml.Operator, this.operator);
console.log("Sdk.FetchXml.condition doesn't require values when the Sdk.FetchXml.Operator.%s operator is used. The values passed were ignored.", enumPropertyName);
}
break;
default:
throw new Error(this.operator + " is an unexpected Sdk.FetchXml.Operator value.")
break;
}
return cNode;
}
//Internal use only
static conditionFromXml(xml) {
var attributeName = xml.attributes.getNamedItem("attribute").nodeValue;
var operator = xml.attributes.getNamedItem("operator").nodeValue;
var conditionObj = new Sdk.FetchXml.condition(<string>attributeName, <Operator>operator);
Sdk.FetchXml.Util.parseAttributes(xml, conditionObj, (conditionObj, name, value) => {
switch (name) {
case "column":
case "entityname":
case "aggregate":
case "alias":
case "uiname":
case "uitype":
conditionObj[name] = value;
break;
case "rowaggregate":
conditionObj.rowAggregate = value;
break;
case "uihidden":
conditionObj.uihidden = Util.convertFetchBoolType(value);
break;
case "value":
conditionObj.addValue(value);
break;
default:
break;
}
})
for (var i = 0; i < xml.childNodes.length; i++) {
if (xml.childNodes[i].nodeName == "value") {
conditionObj.addValue(value.valueFromXml(xml.childNodes[i]));
}
}
return conditionObj;
}
}
@sealed
export class entity {
/**
* Contains the data for a fetchXml entity element.
* @param name The logical name of the attribute
* @param [attributes] The attributes to include with the entity
* @param [orders] The orders to apply to the query
* @param [filters] The filters to apply to the query
*/
constructor(name: string, attributes?: Array<Sdk.FetchXml.attribute>, orders?: Array<Sdk.FetchXml.order>, filters?: Array<Sdk.FetchXml.filter>) {
if (!(this instanceof Sdk.FetchXml.entity))
{ return new Sdk.FetchXml.entity(name, attributes, orders, filters) }
this.name = name;
if (attributes)
this.attributes = attributes;
if (orders)
this.orders = orders;
if (filters)
this.filters = filters;
}
private _allAttributes: boolean = null;
private _attributes: Array<Sdk.FetchXml.attribute> = [];
private _orders: Array<Sdk.FetchXml.order> = [];
private _linkEntities: Array<Sdk.FetchXml.linkEntity> = [];
private _filters: Array<Sdk.FetchXml.filter> = [];
private _name: string;
/**
* Gets or sets whether all attributes for the entity should be returned
*/
public get allAttributes(): boolean {
return this._allAttributes;
}
public set allAttributes(value: boolean) {
if (!Sdk.FetchXml.Util.isBooleanOrNull(value)) {
throw new Error("Sdk.FetchXml.entity.allAttributes must be a boolean value or null.")
}
this._allAttributes = value;
}
/**
* Gets or sets the array of attribute of the entity to be returned in the query results
*/
public get attributes(): Array<Sdk.FetchXml.attribute> {
return this._attributes;
}
public set attributes(value: Array<Sdk.FetchXml.attribute>) {
if (!Sdk.FetchXml.Util.isAttributeArrayOrNull(value)) {
throw new Error("Sdk.FetchXml.entity.attributes must be an array of Sdk.FetchXml.attribute or null.")
}
if (value == null) {
this._attributes = [];
} else {
this._attributes = value;
}
}
/**
* Gets or sets the array of attribute of the entity to be returned in the query results
*/
public get orders(): Array<Sdk.FetchXml.order> {
return this._orders;
}
public set orders(value: Array<Sdk.FetchXml.order>) {
if (!Sdk.FetchXml.Util.isOrderArrayOrNull(value)) {
throw new Error("Sdk.FetchXml.entity.orders must be an array of Sdk.FetchXml.order or null.")
}
if (value == null) {
this._orders = [];
} else {
this._orders = value;
}
}
/**
* Gets or sets the array of related entities to be returned in the query results
*/
public get linkEntities(): Array<Sdk.FetchXml.linkEntity> {
return this._linkEntities;
}
public set linkEntities(value: Array<Sdk.FetchXml.linkEntity>) {
if (!Sdk.FetchXml.Util.isLinkEntityArrayOrNull(value)) {
throw new Error("Sdk.FetchXml.entity.linkEntities must be an array of Sdk.FetchXml.linkEntity or null.")
}
if (value == null) {
this._linkEntities = [];
} else {
this._linkEntities = value;
}
}
/**
* Gets or sets the array of filters to be applied to the query results
*/
public get filters(): Array<Sdk.FetchXml.filter> {
return this._filters;
}
public set filters(value: Array<Sdk.FetchXml.filter>) {
if (!Sdk.FetchXml.Util.isFilterArrayOrNull(value)) {
throw new Error("Sdk.FetchXml.entity.filters must be an array of Sdk.FetchXml.filter or null.")
}
if (value == null) {
this._filters = [];
} else {
this._filters = value;
}
}
/**
* Gets or sets the logical name of the entity
*/
public get name(): string {
return this._name;
}
public set name(value: string) {
if (!Sdk.FetchXml.Util.isString(value)) {
throw new Error("Sdk.FetchXml.entity.name must be a string.")
}
this._name = value;
}
/** @description Adds an attribute to the attribute collection
* @param {Sdk.FetchXml.attribute | string} attributeOrAttributeName the attribute or attribute name to add
* @returns {Sdk.FetchXml.entity}
*/
public addAttribute(attributeOrAttributeName: Sdk.FetchXml.attribute | string) {
if (Sdk.FetchXml.Util.isString(attributeOrAttributeName)) {
// Some saved queries have duplicate attributes defined, so this is a bit more strict than it has to be.
var exists = false;
this.attributes.forEach(function (a) {
if (a.name == attributeOrAttributeName) {
exists = true;
}
});
if (!exists) {
this.attributes.push(new Sdk.FetchXml.attribute(<string>attributeOrAttributeName))
}
return this;
}
if (Sdk.FetchXml.Util.isAttribute(attributeOrAttributeName)) {
var exists = false;
this.attributes.forEach(function (a) {
if (a.name == (<Sdk.FetchXml.attribute>attributeOrAttributeName).name) {
exists = true;
}
});
if (!exists) {
this.attributes.push(<Sdk.FetchXml.attribute>attributeOrAttributeName);
}
}
else {
throw new Error("Sdk.FetchXml.entity addAttribute method attributeOrAttributeName parameter must be an Sdk.FetchXml.attribute or a string value.");
}
return this;
}
/** @description Removes an attribute from the attributes collection by name
* @param {string} attributeName The name of the attribute to remove
* @returns {Sdk.FetchXml.entity}
*/
public removeAttributeByName(attributeName: string) {
Sdk.FetchXml.Util.removeCollectionValueByProperty(this.attributes, "name", attributeName)
}
/** @description Removes an attribute from the attributes collection by reference
* @param {Sdk.FetchXml.attribute} attribute The attribute to remove
* @returns {Sdk.FetchXml.entity}
*/
public removeAttributeByRef(attribute: Sdk.FetchXml.attribute) {
Sdk.FetchXml.Util.removeCollectionValueByRef(this.attributes, attribute);
}
/** @description Removes an attribute from the attributes collection
* @param {Sdk.FetchXml.attribute} attribute The attribute to remove
* @returns {Sdk.FetchXml.entity}
*/
public removeAttribute(attribute: Sdk.FetchXml.attribute) {
Sdk.FetchXml.Util.removeCollectionValue(this.attributes, attribute);
}
/** @description Adds an order to the orders collection
* @param {Sdk.FetchXml.order | string} orderOrAttribute The order to add to the attributes collection or the Attribute property of a new order to create
* @param {boolean} descending Whether the order is descending. True if descending, otherwise false
* @param {string} alias The alias to set for the order
* @returns {Sdk.FetchXml.entity}
*/
public addOrder(orderOrAttribute: any, descending?, alias?) {
if (Sdk.FetchXml.Util.isOrder(orderOrAttribute)) {
this.orders.push(orderOrAttribute);
return this;
}
if (Sdk.FetchXml.Util.isString(orderOrAttribute)) {
this.orders.push(new Sdk.FetchXml.order(orderOrAttribute, descending, alias));
}
else {
throw new Error("Sdk.FetchXml.entity addOrder method orderOrAttribute parameter must be a Sdk.FetchXml.order value or a string.");
}
return this;
}
/** @description Removes a order from the orders collection by reference
* @param {Sdk.FetchXml.order} order The order to remove from the orders collection
* @returns {Sdk.FetchXml.entity}
*/
public removeOrderByRef(order: Sdk.FetchXml.order) {
if (!Sdk.FetchXml.Util.isOrder(order)) {
throw new Error("Sdk.FetchXml.entity removeOrderByRef method order parameter must be an Sdk.FetchXml.order.")
}
Sdk.FetchXml.Util.removeCollectionValueByRef(this.orders, order);
return this;
}
/** @description Removes a order from the orders collection by value