Service Catalog Client Script Glide Record

Steve A
Kilo Expert

I am building a quick form for itil use until we build out the full procurement application. There are 5 variables: requested_by (reference to sys_user), location (reference to location), vendor (lookup select box to core_companies with filter vendor = true&&state=active), description (single line text), purpose(multi line text).

I am working on a onChange client script but getting lost as I try to clarify what is server-side vs what is client-side. The script should run everytime the vendor field changes and needs to GlideRecord the core_companies table to confirm that the u_primary_contact field is not null. if it is null then notify the user. The simple workflow will send an email to the primary contact of the vendor with the form variables thus notifying them of an order. and then the workflow closes the request as it is only record keeping and not the full procurement system. Below is what I have done and i don't believe it has a chance. Any help is appreciated.

find_real_file.png

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

You might also consider modifying the filter on the vendor variable to only show companies where the u_primary_contact field is not null.

View solution in original post

6 REPLIES 6

Mark Stanger
Giga Sage

You're actually pretty close.  Can you paste your script in here so I can modify it for you?

Steve A
Kilo Expert

Nice to know I can even find the ballpark. Thank you.

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   //GlideRecord the company table and make sure the vendor has a primary contact with a valid email address

    var ven = new GlideRecord('core_company');
    ven.addQuery('sys_id', g_form.getValue('vendor'));
    ven.query();
    
    if (ven.next()) {
        if (ven.u_primary_vendor_contact == '') {
            alert("The vendor selected does not have a primary contact listed so we don't know who to email with your request.");
        }
    }
   
}

Give this a quick try and see if it works better.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	//GlideRecord the company table and make sure the vendor has a primary contact with a valid email address
	var ven = new GlideRecord('core_company');
	ven.addQuery('sys_id', g_form.getValue('vendor'));
	ven.query(vendorContactReturn);
}

function vendorContactReturn(ven) {
	if (ven.next()) {
		if (ven.u_primary_vendor_contact == '') {
			alert("The vendor selected does not have a primary contact listed so we don't know who to email with your request.");
		}
	}
}

I tried this code with no luck I then changed the addQuery based on amauryboulom's suggestion with no luck. I may do what Jim suggested and change my reference qualifier to filter u_primary_vendor_contact !=NULL