Attachment Mandtory for a catalog item

nameisnani
Mega Sage

Hi Team ,

 

We have a catalog item called “AWS Support”. Inside it, there is a variable called “Type of Request”.
One of the options for this variable is “Create AWS AD Group”.

If the user selects this option and tries to submit the form without adding an attachment, the form should not be submitted. Instead, the system should show an error message asking the user to attach the required file.

 

nameisnani_0-1755498773072.png

function onSubmit() {

    var requestType = g_form.getValue('type_of_request'); 

    if (requestType == 'Create AWS AD Group') {

        var attachmentCount = g_form.getValue('attachments'); // this only works with attachment mandatory check in later versions

        // For safer check - use g_form.hasAttachments() if your instance supports

        if (!g_form.hasAttachments()) {

            alert("Attachment is mandatory when selecting 'Create AWS AD Group'. Please attach a file before submitting.");

            return false; // Prevent submission

        }

    }

    return true;

}

 

 

 

 

the script which i have written it is not working - what was the error . 

 

@Ankur Bawiskar  

1 ACCEPTED SOLUTION

Hi @nameisnani ,

 

"If the user selects this option and tries to submit the form without adding an attachment, the form should not be submitted. Instead, the system should show an error message asking the user to attach the required file."

 

It looks like - YOu want this field to be mandatory and when user is leaving blank, it should display error.

 

Regards,

Nikhil Bajaj

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

View solution in original post

15 REPLIES 15

Nikhil Bajaj9
Giga Sage

Hi @nameisnani ,

 

Just asking why you ar enot using - Ui Poilcy to make this field mandatory?

 

NOTE:- Please close all your previous threads/questions by making correct answers as- Solution accepted.

Regards,

Nikhil Bajaj

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

@Nikhil Bajaj9 

 

my requriment is to not make field mandtorty . could youpleas check my post once .

Hi @nameisnani ,

 

"If the user selects this option and tries to submit the form without adding an attachment, the form should not be submitted. Instead, the system should show an error message asking the user to attach the required file."

 

It looks like - YOu want this field to be mandatory and when user is leaving blank, it should display error.

 

Regards,

Nikhil Bajaj

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

@Nikhil Bajaj9 

 

"If the user selects this option and tries to submit the form without adding an attachment, the form should not be submitted. Instead, the system should show an error message asking the user to attach the required file."   //// Yes , this is the one i am trying to achieve .

 

could you please tell what was the mistake in my script .

NOTE - I don't to make the filed mandtory .

It looks like - YOu want this field to be mandatory and when user is leaving blank, it should display error. // I am not looking for this .

 

hope you got my request