- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 06:13 AM
How to make a field mandatory on sc_task only when before task state is closed complete in catalog ServiceNow.
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:39 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 10:02 PM - edited 12-19-2023 10:05 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 10:02 PM - edited 12-19-2023 10:05 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 10:37 PM
Glad to know that my approach worked for you.
Please mark my response as correct and close the thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 09:21 PM
Hello @Bheemaraju Vagu
Modify your script as below
Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Vaishnavi Shinde