Skip to content

Commit 06eaf0f

Browse files
authored
Added additional logic
1 parent 5e1e232 commit 06eaf0f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Server-Side Components/Business Rules/Sync Integer Field/sync_integer_field.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,27 @@
1212
tableRecord.query();
1313

1414
while(tableRecord.next()) {
15-
projectList.push(tableRecord.sys_id.toString());
15+
recordList.push(tableRecord.sys_id.toString());
1616
}
1717

18+
//Condition check to make sure the record has a value to add to the arry in the correct spot, otherwise no reason to splice the array
19+
if (current.{{insert name of integer field you want to sync}} != '') {
20+
var index = current.{{insert name of integer field you want to sync}} - 1; //Making this one less so it will get added first
21+
recordList.splice(index, 0, current.sys_id.toString()); //This will insert our record into the correct position it needs to be in the list
22+
}
1823

19-
24+
//Reassigning the integer sequentially
25+
for (var i = 0; i < recordList.length; i++) {
26+
if(recordList[i] == current.sys_id.toString()) {
27+
current.{{insert name of integer field you want to sync}} = i + 1;
28+
} else {
29+
var updatedTableRecord = new GlideRecord(tableName);
30+
if (updatedTableRecord.get(recordList[i])) {
31+
updatedTableRecord.{{insert name of integer field you want to sync}} = i + 1;
32+
updatedTableRecord.setWorkflow(false); //Setting the workflow false since we dont want the flow to get triggered since all we are doing is updating the integer field
33+
updatedTableRecord.update()
34+
}
35+
}
2036

2137

2238
})(current, previous);

0 commit comments

Comments
 (0)