Search and merge records registered at the same date and time(FlowDesigner's action)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 12:35 AM
We would like to match multiple records, each registered at the exact same date and time, and summarize the values in the description.
(ideal)
record 1-1 + record 2-1 = new record 3-1 (description 1-1+2-1)
record 1-2 + record 2-2 = new record 3-2 (description 1-2+2-2)
record 1-3 + record 2-3 = new record 3-3 (description 1-3+2-3)
・
・
・
In the flow action, when record 1 is registered, I search for the description of records 1 and 2 and retrieve/output the value of the description from the hit records,
Each of these works for one record at a time, but if multiple records are registered on the same day and time, the search results will be faulty and will not be processed as ideal.
Is it possible to process each record in such a way that they are ideally linked?
(function execute(inputs, outputs) {
var start_time = new GlideDateTime(inputs.start_time);
var start_offset = new GlideTime();
start_offset.setValue("00:-01:00");
start_time.add(start_offset);
var target = new GlideRecord('u_custom_table');
target.addQuery('u_datetime','>=',start_time); //Date and time of registration -1minutes
target.addQuery('u_datetime','<=',inputs.end_time); //After waiting 1 minute after registration record
target.addQuery('u_state','=','open');
target.orderBy('u_datetime');
target.query();
var value = inputs.values;
var message = value.split(','); //Value to search for(Comma Separated)
var alert = "";
var alert_list = Array(message.length);
var record_list = [];
var numbers = [];
while(target.next()) {
for(var i = 0; i < message.length; i++){
if( numbers.indexOf(i) !== -1){ continue; }
var str = message[i];
if( target.u_description.indexOf(str) !== -1 ){
alert_list[i] = target.getValue('u_description');
numbers.push(i);
record_list.push(target.sys_id.toString());
break;
}
}
}
for(var i = 0; i < message.length; i++){
if(alert_list[i]){
if(alert){
alert += '\n';
}
alert += alert_list[i];
}
}
for(var i = 0; i < message.length; i++){
var str = message[i];
var reg = new RegExp(str,"i");
if( (reg.test(alert) == false) ){
if(alert){
alert += '\n';
}
alert += 'lost message';
break;
}
}
outputs["record_list"] = record_list;
outputs["alert"] = alert;
})(inputs, outputs);