Skip to content

Commit abdeb87

Browse files
Merge 26.7 to 26.9
2 parents ceb4429 + d8f9e68 commit abdeb87

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎LDK/resources/scripts/ldk/Utils.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ LDK.Server.Utils = new function(){
7373
//normalize to a javascript date object
7474
date = new Date(date.getTime());
7575
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
76+
},
77+
78+
/**
79+
* Replaces each named field's value with the case-normalized value from its lookup target, adding an error for any value the target does not contain.
80+
* The helper must be created at script scope: it caches each target's allowable values per instance, so creating one per call would re-read the target table for every row.
81+
*/
82+
normalizeLookupFields: function(helper, row, errors, lookupFields){
83+
for (var i=0;i<lookupFields.length;i++){
84+
var f = lookupFields[i];
85+
var val = row[f];
86+
if (!LABKEY.ExtAdapter.isEmpty(val)){
87+
var normalizedVal = helper.getLookupValue(val, f);
88+
89+
if (LABKEY.ExtAdapter.isEmpty(normalizedVal))
90+
errors[f] = 'Unknown value for field: ' + f + '. Value was: ' + val;
91+
else
92+
row[f] = normalizedVal;
93+
}
94+
}
7695
}
7796
}
7897
}

0 commit comments

Comments
 (0)