Field controls using State Flows does not mark the field mandatory and just throws error message

Ashutosh44
Tera Contributor

Hi SN Experts!

I am creating state flows for a project in CSM.
I have defined some field controls using in each state flow to have the mandatory logic in place.
The problem is When going from one state to another using UI Action (automatically created using State flow)
If the mandatory fields are empty in workspace, the form does not blinks and marks those fields red as it usually happens if we create client scripts/ UI policies.
As you can see in the following image when I click on Start UI Action, I am getting the error message that Assigned to is Mandatory but its not flashing or marking the field as Mandatory.

Ashutosh44_0-1714985652894.png

 

4 REPLIES 4

Mark Manders
Tera Patron

It could be that UI policies or Client scripts are conflicting with your Field controls in the State Flow, so the UI doesn't show the fields as mandatory, but on checking the fields when clicking the button, it does do the validation and shows the error. 

Do fields show as mandatory when done through a UI policy? I saw once that custom UI Themes were in the way (just not showing anything on mandatory fields).


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark,

Yes normal UI policies and Client scripts show the fields as mandatory.
When state flows are created, Client scripts are also created if we add any fields in field controls, I checked that client script and there also g_form.setMandatory function was used, so ideally it should Highlight those fields.
No other client script/ UI policies are conflicting with my state flows.
Any help would be greatly appreciated. Thanks!

DeepakY
Tera Contributor

Hey @Ashutosh44 ,

I am also getting the same issue while working with the state flow.
Is this issue resolved for your project ?.
Any help would be appreciated.

Thanks.

Kailash Bhange
Mega Sage

Hi @DeepakY,

This is down to how state flows split the work between client and server, rather than a bug in your config.

When you add field controls to a state flow, the platform generates:
- an onLoad and an onChange client script for the table ("<table> state flow" / "<table> change state flow"). These are what call g_form.setMandatory and give you the red asterisk/flash.
- a business rule ("State Flow Notes for <table>") that enforces the mandatory fields on save.

The onChange script only runs when the State field changes on the form. The transition button, though, changes the state on the server. So the client never sees the state change, the fields are never marked mandatory on the form, and the business rule rejects the update with just the "X is mandatory" error. That matches what you're seeing.

What has worked to get the normal mandatory behaviour:

1. Put the field controls on the end state (not only on the full start-to-end transition). The docs recommend this, and it means the fields are mandatory whenever the record is in that state or the user picks it from the State choice list.

2. For the button, use a client-side UI action instead of the generated one:
- In the state flow, leave the manual transition without the condition/script that auto-creates the UI action (or deactivate the transition's UI action if you don't need it).
- Create your own UI action on the table: Form button, Client = true, Action name = e.g. start_work, Onclick = startWork().
- Script:

function startWork() {
// set the target state on the form - this fires the state flow onChange script
g_form.setValue('state', '10'); // use your target state value
// submit; the form's mandatory check now highlights the empty fields
gsftSubmit(null, g_form.getFormElement(), 'start_work');
}

if (typeof window == 'undefined') {
current.update();
action.setRedirectURL(current);
}

Keep the same condition you had on the generated action (current state, roles).

3. Leave the "State Flow Notes" business rule as is - it's still your server-side safety net for list edits, APIs, etc.

If your agents work in CSM Configurable Workspace, the classic client script above won't run there - you'd need the Workspace Client Script on the UI action (or a declarative action) doing the same g_form.setValue before saving.

Which release are you on, and is this in the classic form or the workspace? I can tighten the script for your case.

 

If this helps, please mark it helpful or accept it as the solution.