In my previous blog post I described how the naming convention for flows with a Common Data Service (current environment) trigger can be enforced with Power Automate flow, and could be extended for other trigger types like Recurrence and Request based on a Switch action. If flows with the CDS(ce) trigger are the only “target”, there is a simplified flow that can do the job.

Here is the overview of the flow:

First action of the flow after the Recurrence trigger is to initialize a variable to create an array, so I can use the message number as index to get the trigger condition(s) of the listed flows:

createArray('Zero', 'Create', 'Delete', 'Update', 'CreateUpdate', 'CreateDelete', 'DeleteUpdate', 'CreateDeleteUpdate')

The second action will get the list of unmanaged flows in the current environment that contain ‘OpenApiConnectionWebhook’ as (unique) trigger type in the clientdata value of the Process record.

For every unmanaged flow I convert the string-encoded JSON from the clientdata value into “plain” JSON:

json(replace(items('Apply_to_each_Unmanaged_Flow')?['clientdata'],'\"','"'))

Expression to get entityname: (where 50 is the presumed maximum length of the entityname)

substring(string(outputs('Compose_Clientdata')), add(indexOf(string(outputs('Compose_Clientdata')), 'subscriptionRequest/entityname'), 33), indexOf(substring(string(outputs('Compose_Clientdata')), add(indexOf(string(outputs('Compose_Clientdata')), 'subscriptionRequest/entityname'), 33), 50), '"'))

Expression to get trigger condition(s) based on message number as index:

variables('triggerConditions')[int(substring(string(outputs('Compose_Clientdata')), add(indexOf(string(outputs('Compose_Clientdata')), 'subscriptionRequest/message'), 29), 1))]

Expression to get filtering attributes: (where 150 is the presumed maximum length of the filteringattributes)

if(contains(string(outputs('Compose_Clientdata')),'subscriptionRequest/filteringattributes'),concat('(',substring(string(outputs('Compose_Clientdata')), add(indexOf(string(outputs('Compose_Clientdata')), 'subscriptionRequest/filteringattributes'), 42), indexOf(substring(string(outputs('Compose_Clientdata')), add(indexOf(string(outputs('Compose_Clientdata')), 'subscriptionRequest/filteringattributes'), 42), 150), '"')),')'),'')

The prefix is composed of the previous outputs:

concat(outputs('Compose_entityname'), '|', outputs('Compose_Trigger_condition_based_on_message_number'),outputs('Compose_Filtering_attributes'))

In the condition it’s checked if the Process Name does not start with the prefix already. If true, then the
Process Name is composed as follows, keeping the maximum length under 100:

if(greater(length(concat(outputs('Compose_entityname'), '|', outputs('Compose_Trigger_condition_based_on_message_number'), outputs('Compose_Filtering_attributes'),': ', items('Apply_to_each_Unmanaged_Flow')?['name'])),100),substring(concat(outputs('Compose_entityname'), '|', outputs('Compose_Trigger_condition_based_on_message_number'), outputs('Compose_Filtering_attributes'),': ', items('Apply_to_each_Unmanaged_Flow')?['name']),0,100),concat(outputs('Compose_entityname'), '|', outputs('Compose_Trigger_condition_based_on_message_number'), outputs('Compose_Filtering_attributes'),': ', items('Apply_to_each_Unmanaged_Flow')?['name']))

The workflow record is deactivated in the first Update action, and then the workflow name is updated in the second.

In the last Update action the workflow record is activated again.

And Bob’s your uncle.

The post Power Automate the enforcement of naming convention on flows with CDS(ce) trigger: Revisited appeared first on There's Something About Dynamics 365.