Skip to main content
Solved

Get current branch_id?

  • March 27, 2026
  • 5 replies
  • 33 views

Forum|alt.badge.img+2

There is no function for getting the current branch_id right?

 

In dynamic model code, the parameters @model_id and @branch_id are provided. In the full staged control procedure code I do not see how they are obtained.

 

I want to write a script, not dynamic code, and use the SF and IAM DB, so I need to filter by branch_id.

Is this a reliable way of getting the branch_id of the DB you are currently connected to: 

SELECT TOP 1 SF_BRANCH FROM sf_model_info ORDER BY sf_model_info_id desc

unless you start changing the connections between branches and databases, i guess

 

Best answer by Mark Jongeling

Hi Robin,

What I understand is that you want to dynamically grant rights to users with a particular user group. As you cannot do this in IAM, you indeed have to make something yourself to determine whether or not a user may or may not modify a record in a particular state.

You can opt to write a Table-valued function (subroutine) that returns elements from the model in your application. This function is completely generated in the Software Factory, where you have access to the element table and the model_id and branch_id, and then can be deployed in your application.

If you wish to also obtain the user groups of users from IAM, I currently suggest to write a query to give to an Application connector. In your application, make a process flow that obtains the users and user groups via an Application connector, then store the result in your database for further usage.

Some handy information is shared in this blog: All about SQL-typed Control procedures | Thinkwise Community

We also use it for a function called get_dom_elemnts(), which returns all elements of a given domain; also completely generated dynamically. 

 Our template looks like this:

-- All elements of a given SF domain
return
(
select t.elemnt_id, t.db_value, t.transl
from
(
values
-- copy the above selected data records and paste in here
[ELEMENT_SET],
('-', '-', '-', '-') -- Dummy row
) as t(dom_id, elemnt_id, db_value, transl)
where t.dom_id = @dom_id
and t.dom_id <> '-'
)

Ant the control procedure code itself like this:

insert into #prog_object_item
(
prog_object_id,
prog_object_item_id,
order_no,
template_id
)
select
'func_get_dom_elemnt',
@control_proc_id,
10,
@control_proc_id

insert into #prog_object_item_parmtr
(
prog_object_id,
prog_object_item_id,
parmtr_id,
parmtr_value,
order_no,
no_line_when_empty
)
select
'func_get_dom_elemnt',
@control_proc_id,
'ELEMENT_SET',
'('''+ e.dom_id + ''',' +
''''+ e.elemnt_id + ''',' +
''''+ e.db_value + ''',' +
''''+ coalesce(replace(t.transl, '''', ''''''), '[' + e.elemnt_id + ']') + ''')',
99 + row_number() over(order by e.dom_id, e.abs_order_no),
0
from elemnt e
left join transl_object_transl t
on t.model_id = e.model_id
and t.branch_id = e.branch_id
and t.type_of_object = 2 -- Dom element
and t.transl_object_id = e.elemnt_id
and t.appl_lang_id = 'en-US'
where e.model_id = @model_id
and e.branch_id = @branch_id

 

Hope this gives the inspiration you need!

5 replies

Tim de Lang
Moderator
Forum|alt.badge.img+4
  • Moderator
  • March 27, 2026

Hi ​@Robin Liu,

Could you specify exactly what you want to achieve and where you’re looking to add the script?

Generally the model and branch id’s are provided to you as parameters, given you work in the context of a model and branch.

Is this a reliable way of getting the branch_id of the DB you are currently connected to: 

SELECT TOP 1 SF_BRANCH FROM sf_model_info ORDER BY sf_model_info_id desc

That will tell you what the branch name of the SF itself is. I assume you want information about your model and branch, not that of the SF?

Thanks,

Tim de Lang


Forum|alt.badge.img+2
  • Author
  • Sidekick
  • March 30, 2026

@Tim de Lang 

my users want to configure authorization such that certain user groups can change a record to a certain status and other user groups cannot, depending on the value of a column in the record.

the status is a domain with elements.

so i am creating a view that represents a matrix of element - user group - column value combinations and whether the status should be available or not, and use it as look up in a task to change the status.

currently i just wrote in the script which elements there are, but i would like to select the elements from the SF table elemnt. i would need to filter this on branch_id, and in the control procedure of a view i am not provided with @branch_id AFAIK


Forum|alt.badge.img+2
  • Author
  • Sidekick
  • March 31, 2026

SELECT TOP 1 SF_BRANCH FROM sf_model_info ORDER BY sf_model_info_id desc

That will tell you what the branch name of the SF itself is. I assume you want information about your model and branch, not that of the SF?

 

by the way, what do you mean with this?

do the sf_model and sf_branch columns of the sf_model_info_id table in my branch/application databases not give the model_id and branch_id that are referred to in Software Factory tables?

it seems like they contain the same branch and model names


Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • Answer
  • March 31, 2026

Hi Robin,

What I understand is that you want to dynamically grant rights to users with a particular user group. As you cannot do this in IAM, you indeed have to make something yourself to determine whether or not a user may or may not modify a record in a particular state.

You can opt to write a Table-valued function (subroutine) that returns elements from the model in your application. This function is completely generated in the Software Factory, where you have access to the element table and the model_id and branch_id, and then can be deployed in your application.

If you wish to also obtain the user groups of users from IAM, I currently suggest to write a query to give to an Application connector. In your application, make a process flow that obtains the users and user groups via an Application connector, then store the result in your database for further usage.

Some handy information is shared in this blog: All about SQL-typed Control procedures | Thinkwise Community

We also use it for a function called get_dom_elemnts(), which returns all elements of a given domain; also completely generated dynamically. 

 Our template looks like this:

-- All elements of a given SF domain
return
(
select t.elemnt_id, t.db_value, t.transl
from
(
values
-- copy the above selected data records and paste in here
[ELEMENT_SET],
('-', '-', '-', '-') -- Dummy row
) as t(dom_id, elemnt_id, db_value, transl)
where t.dom_id = @dom_id
and t.dom_id <> '-'
)

Ant the control procedure code itself like this:

insert into #prog_object_item
(
prog_object_id,
prog_object_item_id,
order_no,
template_id
)
select
'func_get_dom_elemnt',
@control_proc_id,
10,
@control_proc_id

insert into #prog_object_item_parmtr
(
prog_object_id,
prog_object_item_id,
parmtr_id,
parmtr_value,
order_no,
no_line_when_empty
)
select
'func_get_dom_elemnt',
@control_proc_id,
'ELEMENT_SET',
'('''+ e.dom_id + ''',' +
''''+ e.elemnt_id + ''',' +
''''+ e.db_value + ''',' +
''''+ coalesce(replace(t.transl, '''', ''''''), '[' + e.elemnt_id + ']') + ''')',
99 + row_number() over(order by e.dom_id, e.abs_order_no),
0
from elemnt e
left join transl_object_transl t
on t.model_id = e.model_id
and t.branch_id = e.branch_id
and t.type_of_object = 2 -- Dom element
and t.transl_object_id = e.elemnt_id
and t.appl_lang_id = 'en-US'
where e.model_id = @model_id
and e.branch_id = @branch_id

 

Hope this gives the inspiration you need!


Forum|alt.badge.img+2
  • Author
  • Sidekick
  • March 31, 2026

@Mark Jongeling 
I wasn’t aware of the assignment type “SQL” yet, thanks!

And it is also helpful to know what a recommended way of interacting with IAM is