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

@asaha 

 

As per your steps . I have created script include 

nameisnani_0-1755503917239.png

nameisnani_1-1755503959812.png

 

 

as per my condtion when type of request is slected - create aws ad group .  while doing testing without adding a attacment  form got submitted .

 

could you please look into that 

asaha
Tera Contributor

First rename the script include as :
CheckAttachment

asaha
Tera Contributor

Application scope: All application scope

And test once. If still not working. Replace line 47 to 56 in your clinet script with

 ga.getXMLAnswer(function(response) {
        if (response === 'false') {
            alert("Please attach something before submitting this request.");
            return false;
        }
}
    });

 

    return true;
}

GlideFather
Tera Patron

Hi @nameisnani 

 

on that particular catalog item - create a new variable with type attachment:

GlideFather_0-1755503017828.png

 

And then make it visible and mandatory like any other variable (catalog UI policy or catalog client script)...

 

NOTE: if you need this approach for more catalog items then make it a variable set and apply the logics on it, then you will be just adding one variable set and it will not require to create the catalog client script or catalog ui policies again and again..

 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Sourabh Tarlekr
Kilo Sage

Hi @nameisnani 

 

Please check the link CheckAttachment  for the solution. There should have a record in the "sys_attachment" table with table name as "sc_cart_item".

 

Regards,

Sourabh