How to run 2 onSubmit client scripts based on different conditions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:02 AM
How to run 2 onSubmit client scripts based on different conditions. when I am trying to run it, both the scripts are running. In this 2 client scripts the only difference is management level condition. but it is showing both the confirm boxed from both the client scripts.
1st Client script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:11 AM - edited 10-17-2023 12:12 AM
Can you try -> if (managementLevel == 12 || managementLevel ==13) and see if this helps
You need to do same for 1st client script.
What you have written is essentially passing for all criteria values.
Best regards
Suyog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:16 AM
I agree with @Suyog Aptikar , you need to include the variable. Also the first script lacks the closing brackets but maybe that is just in your post.
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:29 AM
or perhaps if (managementLevel <12) for the first script and if (managementLevel >=12) for the second. I would also recommend to combine the logic into one script. Makes it a lot easier to maintain.
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:08 PM - edited 10-17-2023 06:11 PM
Hi @Pratiksha Lang1 how are you?
I made this code.
function onSubmit() {
//Type appropriate comment here, and begin script below
var refusalStatus = g_form.getValue('u_refusal_status'),
refusalReason = g_form.getValue('u_refusal_closure_reason'),
managementLevel = g_form.getValue('u_management_level'),
managementLevelCondition1 = [6,7,8,9,10,11],
managementLevelCondition2 = [12,13],
textMessage;
if((refusalStatus == 'invalid') && (refusalReason == 'Continues to disagree')){
//Get the Text Message
if(managementLevelCondition1.indexOf(managementLevel) != "-1"){
textMessage = "if refusal reason is chosen as Invalid then a Warning Letter will be sent to the employee. Do you want to proceed?"
}else if(managementLevelCondition2.indexOf(managementLevel) != "-1"){
textMessage = "Selecting Refusal Closure Reason as 'Continues to disagree' will result in issuance of a redundancy letter"
}
/* Show the modal if has Message */
if(textMessage){
var answer = confirm(textMessage)
if(answer){
// I have selected dummy fields but you can select as per your needs
}
else{
g_form.setValue('u_refusal_status', '');
g_form.setValue('u_refusal_closure_reason', '');
return false
}
}
}
It basically unifies the two Client Script on Submit, reusing the variables and conditions.
As the conditions are very similar and the behavior of both scripts is the same, you can unify the conditions and just change the popup text
If my answer helped you, please mark my answer as helpful.
Vanderlei Catione Junior | LinkedIn
Senior ServicePortal Developer / TechLead at The Cloud People