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

Hi @Bheemaraju Vagu \

Please provide inputs on my question.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Sainath N
Mega Sage
Mega Sage

@Bheemaraju Vagu : Please refer to the article below, which explains in detail the implementation for your similar use case.

 

https://www.servicenow.com/community/now-platform-blog/what-is-the-best-way-to-make-catalog-task-var...

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
 
Regards,
Sainath N

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

@Ankur Bawiskar 

Not working

 

 

@Bheemaraju Vagu 

Did you try adding alert and see?

It should be normal onSubmit client script on sc_task and not catalog client script

I hope you have taken care of that

Please share screenshot of your client script configuration

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