The CreatorCon Call for Content is officially open! Get started here.

Check for Attachments if a field is blank.

turnea
Mega Expert

Hi everyone,

I've seen a lot of script for checking attachments, but I can't seem to track one down that is conditional on whether or not a catalog variable is blank.   I have this portion already:

function onSubmit()

{

    var cat_id = gel('sysparm_item_guid').value;

    var gr = new GlideRecord("sys_attachment");

    gr.addQuery("table_name", "sc_cart_item");

    gr.addQuery("table_sys_id", cat_id);

    gr.query();

    if (!gr.next()) {

          alert("Attach manager and/or site manager's approval email for cart movement");

          return false;

    }

                     

}

I know that I need to add something to this that checks one variable and if it returns "null" to make it mandatory for attachments.   Any help would be appreciated.

Thank you,

Amandah

1 ACCEPTED SOLUTION

acretion
Tera Expert

Amandah,



If i'm understanding your question, you'll probably just need to add an additional if condition at the top of the script, something like...(i haven't tested this, fair warning)



function onSubmit()


{


          if (g_form.getValue('FIELD_NAME') == '')   { //replace with whatever your catalog variable name is


                var cat_id = gel('sysparm_item_guid').value;


                var gr = new GlideRecord("sys_attachment");


                gr.addQuery("table_name", "sc_cart_item");


                gr.addQuery("table_sys_id", cat_id);


                gr.query();


                if (!gr.next()) {


                      alert("Attach manager and/or site manager's approval email for cart movement");


                      return false;


                }


      }


}


View solution in original post

5 REPLIES 5

Hi Christopher,



I was able to try it out and it worked exactly as expected.   Thank you for your assistance!



Amandah