Can we set conditions on catalog client scripts?

gnunez
Kilo Guru

Hello all,

I am creating a catalog item and the first question is "Are you opening this request on behalf of someone else?" if they select No then I want the catalog client scripts to trigger because it'll prepopulate the other fields with first name, last name, employee id, etc. If they select Yes I do not want the client scripts to trigger because the user should fill out those fields manually.

Are conditions on catalog client scripts possible or would anyone recommend another best practice for this scenario?

Thanks in advance,

Grace

1 ACCEPTED SOLUTION

Can you try this if your issue not solved yet.
I assume OPENED_BY field is there on catalog item and it already have the current user's record

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	var request_behalf = g_form.getValue('request_behalf');
	if(request_behalf == 'request_no'){
		g_form.setValue('first_name', g_user.firstName);
		g_form.setValue('last_name', g_user.lastName);
		var emp = g_form.getReference('opened_by', setEmpID);
	}
	else
		return;
}
function setEmpID(emp){
	g_form.setValue('empid', emp.employee_number);
}

View solution in original post

17 REPLIES 17

In your IF loop, you will have to use setValue method to populate those fields.

first_name, last_name, empid are initially empty and do you want to populate them from user table with the info of user who ever is logged in ?

Okay I'll try that. The way I currently get the user info is by referencing the opened by user see an example below

function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}

g_form.getReference('opened_by', setEmpID);
}

function setEmpID(ref){
g_form.setValue('empid', ref.employee_number);
}

 

This is what I have for each field (first name, last name, phone number, etc.)

I guess you already have working solution in retrieving values, you can keep it.

To populate them into your catalog item, use setValue method in your IF loop of your first posted script.

g_form.setValue('catalog_item_variable_name', valueToSet);//valueToSet is temp variable holding the value that you want to populate into your catalog item.

Please let me know if you have any questions.

 

Thanks

Ashok

Thanks Ashok you've been very helpful and patient with me being such a newbie at this!

So I have the below:

find_real_file.png

I think, this should be like,

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var request_behalf = g_form.getValue('request_behalf');
if(request_behalf == 'request_no'){ // Please check if request_no is a right choice value.
g_form.setValue('first_name', g_user.firstName);
g_form.setValue('last_name', g_user.lastName);
g_form.setValue('empid', g_user.userID);
}
}