- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 02:06 AM
Hello Developers,
I wanted to make few fields mandatory while closing the stask.
I used below script & it is working fine.
But I also want to add few things like, If user is in a different view where these fields are not visible on form then these should not be mandatory.
Do we have any line of code which check, If these fields are on the form?
If yes, then fill them(mandatory)
If No, ignore (non-mandatory)
function onSubmit() {
//Type appropriate comment here, and begin script below
var state = g_form.getValue('state');
var solution = g_form.getValue('u_solution');
var assign = g_form.getValue('assigned_to');
if ((state == 3 || state == 10) && (solution == '')) {
g_form.showFieldMsg('u_solution', 'Please fill solution before closing the Task', 'error');
// alert('Please fill solution field before closing the Task');
return false;
}
if ((state == 3 || state == 10) && assign == '') {
g_form.showFieldMsg('assigned_to', 'Please fill Assigned to before closing the Task', 'error');
return false;
}
}
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 02:35 AM
You can use the below like to check if the field is present on the form(current view)
g_form.hasField('<your field name>') //returns true fi field is present, false if it is not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 02:09 AM
This is not expected buddy, if field are not on Form then how user will know that it is mandatory
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 02:57 AM
That's why I want to make a check, If fields is visible on form or not.
If yes, Mandatory
If no, Non-Mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 02:11 AM
Hi Naveen,
You can use something like below to check the view and make the fields Mandatory based on them
var view = getView();
if (view == '<view name>'){
//make fields mandatory
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 02:31 AM
Hi Anurag,
Not specifically to 1 view,
This will be better for future too, I want to check if fields is available on form, If yes then Mandatory else not.
Please suggest