Catalog SC_task

Bheemaraju Vagu
Tera Expert

How to make a field mandatory on sc_task only when before task state is closed complete in catalog ServiceNow.

BheemarajuVagu_0-1702994419927.png

Requirement is :

 

1.When state is closed completed and without filling the above email field we couldn't update it.

2. Email field should become mandatory when we select state as closed completed rest should be same as above?

 

Kindly provide me the solution?

 

 

what I did in catalog client script.

 

function onSubmit() {
    if (g_form.getValue('state') == '3') {
        if (g_form.getValue('short_description') == 'Bundle 5 - New UserAccount') //to make this variable mandatory when only this task closes
        {
            g_form.setMandatory('u_please_enter_your_e_mail_address', true);

            return false;
        }
    }
}
 
 
But it is not working...
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Bheemaraju Vagu 

this will work fine

function onSubmit() {
	if (g_form.getValue('state').toString() == '3') {
		if (g_form.getValue('short_description') == 'Bundle 5 - New UserAccount') //to make this variable mandatory when only this task closes
		{
			g_form.setMandatory('variables.u_please_enter_your_e_mail_address', true);
			return false;
		}
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@Ankur Bawiskar 

 

I got resolved the issue.

I did the following script in Onchange().

 


function Onchange() {
var state = g_form.getValue('state');
var s_des = g_form.getValue('short_description');
g_form.addErrorMessage(state);
g_form.addErrorMessage(s_des);

if (state == "3" && s_des == "Bundle 5 - New User Account") {
g_form.setMandatory('variables.u_please_enter_your_e_mail_address', true);
} else {
g_form.setMandatory('variables.u_please_enter_your_e_mail_address', false);
}
}

  

View solution in original post

17 REPLIES 17

@Ankur Bawiskar 

Can we write OnChange() catalog client script?

Plz share that

@Ankur Bawiskar 

We need the script before submit the sc_task. Can we try onchange?

@Bheemaraju Vagu 

yes you can write onChange client script on State field on sc_task

then make it mandatory by checking if it's empty

Can you share onSubmit client script configuration screenshot?

The script I shared should work fine

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Yes, working fine but after submitting the task the field is getting mandatory.

But we need to make it mandatory when  we change state to closed complete.

@Bheemaraju Vagu 

 

Instead of creating catalog client script create onChange client script on SC_Task table.

In script section add below script.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
if(newValue == '3' && g_form.getValue('cat_item') == 'your item sys_id'){
g_form.setMandatory('variables.manager',true);
}
 
   //Type appropriate comment here, and begin script below
   
}
 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Vaishnavi Shinde