How to set Serial Numbers in a Portal

My portal has a sort order based on a number field. The sort field is exposed in the portal and it is possible to modify the sort order manually. Rather than modify every item I can use fractions, such as 3.1, 3.2, 3.3, and the sorting ensures they display between the lines 3 and 4. I can then select the sort field and use the Replace Field Contents, replacing with serial numbers starting at one and incrementing by one. That action respects the sort order in the portal, so that 3, 3.1, 3.2, 3.3, 4 gets resequenced as 3, 4, 5, 6, 7.

Now I want to script that process. In my attempts so far, the Replace Field Contents script step doesn't respect the portal sort order. It uses the creation order of the records, not the sort order of the portal.

I can walk-the-tree but I wonder if anyone knows how to tame the Replace Field Contents script step?

You can refresh the portal prior to the Replace Field Content. Use the Refresh Portal or Commit Record script step. Be careful when replacing in a portal. The portal of every record in the found set will be affected.

You can alternatively perform the Replace Field Content in a layout based on the portal's table: Commit the record to avoid record locking issues; Isolate the related records in a layout based on the portal's table by performing a find based on the relationship predicates or by using Go To Related Records; Sort the records; Replace field content; Return to the original layout.

I have been refreshing the portal prior to running the script. That is necessary to get the right sort order for doing this manually. It doesn't affect the result when the script is used.

Thanks for the reminder that replacing in a portal affects all portal rows of every record in the found set! :nauseated_face:

I forgot to add a detail. Sort the related data via the relationship, not via the portal.

1 Like