Set catalog variable mandatory based on sc task state

Avee90
Tera Contributor

Hello folks,

     I've a requirement to set a catalog variable mandatory based sc task state choice. I tried using catalog script but it is not working. Can anyone help is it doable or not?

Thanks

 

 

2 REPLIES 2

Deepak Shaerma
Kilo Sage

Hi @Avee90 
your script is almost correct, you just need some moifications in it....

// Assuming ‘state’ is a variable on the catalog item. If it’s a field on the task, you’d need to approach it differently.
var state = g_form.getValue('state');

// Assuming ‘short_description’ is a variable. If it’s a field, this approach is fine. 
// Otherwise, for a variable, you use g_form.getValue(‘variable_name’);
var sd = g_form.getValue('short_description');

if (sd === 'Please attach the template') {
    if (state === '3') { // Assuming state ‘3’ is the value representing the desired choice, and it’s captured as a string
        g_form.setMandatory('upload_the_template', true);
    } else {
        // Optionally, make it not mandatory if the condition is not met
        g_form.setMandatory('upload_the_template', false);
    }

Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma 

dgarad
Giga Sage

HI @Avee90 

 

 check the below code.

var state = g_form.getValue('state');
var sd = g_form.getValue('short_description');

if (sd === 'Please attach the template') {
    if (state = 3) { // state 3 is the value representing  integer value
        g_form.setMandatory('upload_the_template', true);
    } else {
        
        g_form.setMandatory('upload_the_template', false);
    }

 

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad