Make a field Mandatory on task table based on its variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 05:42 PM
Hello community,
We have 1 custom field named asset on sc_task table and there are some variables on the form also. My requirement is, i want to make the asset field mandatory only when Asset type variable is eus and state changes to closed complete.
Any help how to get variable value and make a proper conditions through ui policy scripts or from client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 05:59 PM
@Deepak Shaerma Try below steps if helps you:
Create a UI Policy on the sc_task table.
Set the Conditions:
State is Closed Complete.
Use a Script condition to check the value of the variable (since variable values are not directly accessible in UI Policy conditions).
UI Policy Script:
// Script condition
(function() {
var assetType = g_form.getValue('variables.asset_type'); // Replace 'asset_type' with the actual variable name
return assetType === 'eus';
})();
UI Policy Action:
Set the asset field to Mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 06:05 PM
You can use a Client Script on the sc_task table. Use any of the g_form methods, like getValue, setMandatory... specifying either the field name or a variable name - the syntax doesn't change so you can use g_form.getValue('state') and g_form.getValue('variable_name')
Following your example, it sounds like an onChange Client Script when State changes is your best bet:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == 3) { //Closed Complete
if (g_form.getValue('v_asset_type') == 'eus') { //variable name and value
g_form.setMandatory('u_asset', true); //custom field name
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 05:56 PM
This is helpful. Thanks @Brad Bowman