# Set Next Related Record

This topic is 4363 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

In the system we are working on there is a jobs table and a phase table, with each job having a series of related phases. In the job table there are key fields to house the phaseId of the current phase (_zkfCurrentPhaseID), and also the PhaseID of the next phase (_zkfNextPhaseID) in the production cycle. I need a way in a script to evaluate the current phase of production and set _zkfNextPhaseID to the recordID of the next related record. Because of how phases are added to the production cycle we can't just take the current ID and add 1 to it. It has to be the next related record ID.

Any suggestions would be greatly appreciated. Thanks so much.

##### Share on other sites

Couldn't you calculate the next phase from the current phase and List ( Phases::PhaseID )?

##### Share on other sites

Couldn't you calculate the next phase from the current phase and List ( Phases::PhaseID )?

I haven't worked much with the list function. The calculation that you suggest gets me a list of phases for the current job, which is cool, but I'm not sure how to use that to get the next list value to use in a Set Field step in my script.

##### Share on other sites

Try =

```Let ( [

v = List ( Phases::PhaseID ) ;

i = ValueCount ( Left ( v ; Position ( ¶ & v & ¶ ; ¶ & CurrentPhaseID & ¶ ; 1 ; 1 ) ) )

] ;

GetValue ( v ; i + 1 )

)```

Note that this assumes that phases are created in order, or that the relationship is sorted in the correct order.

to use in a Set Field step in my script.

I don't see why you need a script here. Select the current phase, and the next phase ID is automatically calculated.

Another option is to define a second relationship as:

Jobs::CurrentPhaseID < Phases 2::PhaseID

The next phase is the first related record through this relationship (again, assuming creation order is the correct order).

##### Share on other sites

This is going to work perfectly for what we are trying to do. Thank you so much for you help.

##### Share on other sites

This topic is 4363 days old. Please don't post here. Open a new topic instead.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account