onSubmit Client Script to make the Add'l comments mandatory based on an Assignment Group change?...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 04:09 PM
Hi All,
I've searched this forum a lot & was not able to find an additional solution. I am hoping that someone can help me with a code for an onSubmit client script.
Originally my task to make the additional comments mandatory based on a change to the assignment group was working but some users were able to bypass the client script if they changed the State field. So I figured an onSubmit client script would be better but I am having trouble with the code.
Original code to previous task below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if ((newValue != oldValue) && (oldValue != ' '))
{
g_form.setMandatory('comments', true);
g_form.addInfoMessage('Additional comments are required prior to changing the Assignment group.');
}
}
Is it a way I can make this to an onSubmit version?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 06:40 PM
I believe you can check this condition in onChange client script itself just update the script as below and rest all things would be automatically handled:
Assuming you have written onChange client script on "Assignmentgroup"
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.setMandatory('comments', "true");
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 07:04 PM
Hi! See the thing is I was using onChange at first but users were able to bypass the mandatory additional comments (when changing the assignment group) by changing the state. So the client script was basically no longer working thats why I'm looking into onSubmit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 09:20 PM
what is the behaviour when users are changing the state, have it made the assignment group empty? if SO you can remove newValue=="" parameter from the same script and test it once:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) { //removed newValue
return;
}
g_form.setMandatory('comments', "true");
}
I believe we don't find any trigger in onSubmit client script in which we get to know that assignment group has updated
Second way of doing the same is before - update BR
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 10:02 PM
So apparently when creating an INC the user will receive the information & fill out the form as instructed. With the onChange client script that I previously had the user would add in an Assignment group & get flagged to fill in the Additional comments, but if the user was to insert the assignment group, ignore the error message & change the State to "In Progress" or even "On hold" the additional comments will no longer be mandatory & the ticket can be submitted. That is why I went the onSubmit route but the code I created (below) from someone that previously responded to this post/deleted & it is still not working. It's requiring the user to add into the additional comments for any field change instead of just the assignment group. See below.
function onSubmit(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ag = g_form.getValue('assignment_group');
if ((ag != oldValue) && (oldValue != ' '))
function onSubmit() {
g_form.setMandatory('comments', true);
g_form.addErrorMessage('Additional comments are required when changing the assignment group.');
return false; // stop the form submission
}
}
Hoping this makes sense!