-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsyncSomeSelections.txt
More file actions
44 lines (39 loc) · 2.15 KB
/
Copy pathsyncSomeSelections.txt
File metadata and controls
44 lines (39 loc) · 2.15 KB
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
TRACE [Running syncSomeSelections snippet https://bit.ly/2unjnbX];
// This script allows to define a number of fields as "global" fields even when used within
// an alternate state. With that, you've got "almost alternate states". Typically, that are
// date fields (year, month, ...) which should act as global, whereas all other selections
// should be private within an alternate state (which they are by default)
// This script snippet will create three variables, two of which you can use within/or as a
// set analysis. vSyncSelAll and vAddSyncSel
// Usage examples:
// Sum ( $(vSyncSelAll) Sales)
// Sum ( {< field = {"value"} $(vAddSyncSel) >} Sales)
// See https://www.youtube.com/watch?v=jQVzMaxABNA
// To tell the script, which field(s) you want to sync into the alternate states, put
// a pattern match list (in single quotes, comma-separated) into variable vSyncFields
// before including the below lines of script, for example
// SET vSyncFields = [ 'order_date*' , 'employee_id', 'shipping_date*' ];
WHEN Len(Trim('$(vSyncFields)'))=0 SET vSyncFields = ['*'];
SET vFieldsWithSelections = [=Replace('ValueList('&CHR(39)&GetCurrentSelections('*/,'&CHR(39),CHR(39)&'/*','',1,'$')&'*/)','ValueList(''*/)','Null()')];
SET vOpenSet = ['{<'&];
SET vCloseSet = [&'>}'];
SET vSetSep = [','&];
SET vMarker1 = ['/*`*/'&];
SET vMarker2 = [&'/*´*/'];
SET vFixEmptySet = ['/*`*/{<>}/*´*/',''];
SET vFixEmptySep = ['/*`*/,/*´*/',''];
SET vSyncSel = Concat(If(WildMatch(§(vFieldsWithSelections), §(vSyncFields))
,'[' & §(vFieldsWithSelections) & '] =P({$}[' & §(vFieldsWithSelections) & '])' ), ' , ');
LET vSyncSel = Replace(vSyncSel, '§(', '$' & '(');
//$Fix: MAPPING LOAD '§(', '$' & '(' AUTOGENERATE(1);
//LET vSyncSel = MapSubString('$Fix', vSyncSel);
LET vSyncSelAll = '=Replace(' & vMarker1 & vOpenSet & vSyncSel & vCloseSet & vMarker2 & ', $(vFixEmptySet) )';
LET vAddSyncSel = '=Replace(' & vMarker1 & vSetSep & vSyncSel & vMarker2 & ', $(vFixEmptySep) )';
// Delete all the temp variables
LET vMarker1 = Null();
LET vMarker2 = Null();
LET vOpenSet = Null();
LET vCloseSet = Null();
LET vSetSep = Null();
LET vFixEmptySet = Null();
LET vFixEmptySep = Null();