g_form.setMandatory in client script is not working on the workspace but working in native view.

Sathwik1
Tera Expert

 

g_form.setMandatory in client script is not working on the workspace but working in normal view.



OnChange Client script

OnChange Field Name : Account

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
var gId = '1234493d47ba6a507c23de79116d7890';
if (newValue ===gId) {
g_form.setMandatory('service', false);
g_form.setMandatory('subcategory', false);
} else {
g_form.setMandatory('service', true);
g_form.setMandatory('subcategory', true);
}

return;
}
gId = '1234493d47ba6a507c23de79116d7890';
if (newValue ===gId) {
g_form.setMandatory('service', false);
g_form.setMandatory('subcategory', false);
} else {
g_form.setMandatory('service', true);
g_form.setMandatory('subcategory', true);
}
}

@Ankur Bawiskar 

11 REPLIES 11

@Sathwik1 

The issue you're facing with your onChange client scripts not working as expected in the workspace could be due to the different behavior of forms and events in the workspace compared to the standard form view.

Please verify with alternative best approach "UI Policy"

adityahubli
Tera Guru

Hello @Sathwik1 ,

I tried the different scenario in my PDI, and the client script works correctly in Workspace.
It may not work in your PDI due to the following reasons:

  1. Incorrect field or variable ID

  2. Isolate Script option is enabled (disable it and test)

  3. Using === (triple equals), which checks both value and data type

Best Practice:
Instead of scripting, this requirement can be achieved using a UI Policy.
Configuration-based solutions are recommended over scripting whenever possible, as they are easier to maintain and follow platform best practices.

 

you can refer following attachments :

 

adityahubli_0-1767688629614.png

 

adityahubli_1-1767688678740.png

 

adityahubli_2-1767688722363.png

 

If this helps you then mark it as helpful and accept as solution😊.

Regards,

Aditya ,

Technical Consultant