Home > Forum > General > Get a total # of records for an application

Get a total # of records for an application
0

Maybe this is simple and I'm just overthinking it.

I'm creating new proposals, each new proposal has an automatically generated # associated with it (PFY2021-xxxx). I have the form rule built to create the string, but I need the number portion to append.

The xxxx number needs to increment for each new record entered. I can't seem to create an "application wide" variable that I can reference, create a new proposal # and then increment by 1.

Now that I think about it like that, can I SQL query the # of records for the workflow? (Still fairly new to queries in webcon, any help would be appreciated).

Thanks

MVP

Hi Bo,

the system internally tracks the number of created workflow instances. By default this is tracked per workflow but can be changed to take the business entity into account as well as a date field. in case the numbering should start again with each new year, you could use the automatic instance numbering based on a form field. I added an attachment with such a setup.

If this is not sufficient you can fall back to an SQL query. In case you need a more specialized selection you can either use the table WFElements or the view V_WFElements, the later once contains additional information about the process (DEF fields), application and others.

SELECT 'PFY'+cast(DatePart(Year,GETDATE()) as varchar(4)) + '-' +cast((
SELECT Count(*)+1
FROM [dbo].[V_WFElements]
where APP_ID = {APP_ID}
)
as varchar(10)) as sample

Edit:
I only tested the query in the Designer and I have forgotten to test it by starting a workflow. It could be that you need to increase the count by 1. I'm not sure about dirty reads in this case.
But I can tell that something like this works. I once ha a sub workflow which signature was made up from the parent workflow signature and the number of created sub workflows.

Edit 2:
It was necessary to move the SQL query to a business rule which is called in turn. Directly using the SQL query inside the Instance number caused an error.