Skip to main content
Answer

Get ID value from row

  • November 21, 2024
  • 6 replies
  • 62 views

Dennis1690
Vanguard
Forum|alt.badge.img+4

Hi, im trying to retrieve the parent_row_id from a newly added row. However @ and T1 both dont work. Anyone knows how I should fix this?

select top 1 step_nr + 1from calculation_step--where calculation_method_id = t1.calculation_method_id «order by step_nr desc

 

 

Best answer by Mark Jongeling

Okay, that clears it up. I'm afraid you will not be able to use t1. nor @something, because Default value expressions cannot do that: Data model | Thinkwise Documentation

Query - The expression used to determine the default value. The query cannot use values from a new record.

Examples: getdate() or dateadd(month, 1, getdate())

The correct way to do what you would like to achieve is using Default logic. In here you can access all the data of the current row and you will be able to set the column value.

It will most likely be similar to this:

if @cursor_from_col_id is null -- Initially
and @default_mode = 0 -- Insert
or @step_nr is null -- If for some reason it has no value, set a value
begin
select top 1 @step_nr = s.step_nr + 1
from calculation_step s
where s.calculation_method_id = @calculation_method_id
order by s.step_nr desc
end

Hope this helps!

This topic has been closed for replies.

6 replies

Mark Jongeling
Administrator
Forum|alt.badge.img+23

Hey Dennis,

Is this a Default value expression for a Task parameter? Or for a different object?


Dennis1690
Vanguard
Forum|alt.badge.img+4
  • Author
  • Vanguard
  • November 21, 2024

For a datamodel column.


Mark Jongeling
Administrator
Forum|alt.badge.img+23

Can you show the datamodel? I'm trying to understand what your goal is and possibly can give an alternative.


Dennis1690
Vanguard
Forum|alt.badge.img+4
  • Author
  • Vanguard
  • November 21, 2024

calculation_method 1 - * calculation_step

When adding a new calculation step row it should take the maxvalue step_nr and add + 1. It should filter on the calculation_method_id, because steps belong to methods.

Is that sufficient enough?

Error message for reference:

 

 


Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • Answer
  • November 21, 2024

Okay, that clears it up. I'm afraid you will not be able to use t1. nor @something, because Default value expressions cannot do that: Data model | Thinkwise Documentation

Query - The expression used to determine the default value. The query cannot use values from a new record.

Examples: getdate() or dateadd(month, 1, getdate())

The correct way to do what you would like to achieve is using Default logic. In here you can access all the data of the current row and you will be able to set the column value.

It will most likely be similar to this:

if @cursor_from_col_id is null -- Initially
and @default_mode = 0 -- Insert
or @step_nr is null -- If for some reason it has no value, set a value
begin
select top 1 @step_nr = s.step_nr + 1
from calculation_step s
where s.calculation_method_id = @calculation_method_id
order by s.step_nr desc
end

Hope this helps!


Dennis1690
Vanguard
Forum|alt.badge.img+4
  • Author
  • Vanguard
  • November 21, 2024

Thanks, will see to it straight away.