Help in my code

Arthur Sanchez
Giga Guru

I'm trying to create a code where, every time a ticket is created, the queue field is updated, and as it's going to be a lot, I thought about creating a client script instead of using flow, + I'm not able to change the queue field

 

 

// Client Script to direct a ticket to a queue based on the fields filled in the catalog tree
function onSubmit() {
    var area = g_form.getValue('area');
    var system = g_form.getValue('system');
    var serviceType = g_form.getValue('service_type');
    
    // Determine the queue based on the field values
    var queueValue = determineQueue(area, system, serviceType);
    
    // Update the 'Queue' field with the correct value
    g_form.setValue('queue', queueValue);
}

// Function to determine the queue value based on the field values
function determineQueue(area, system, serviceType) {
    // If the area is TI, the system is "app", and the service type meets the criteria
    if (area === 'ti' && system === 'app' &&
        (serviceType === 'maintenance_ti' || serviceType === 'installation_ti' ||
         serviceType === 'configuration_ti' || serviceType === 'customization_ti')) {
        return 'app_n1'; // Queue value for app_n1
    }
    
    // If no case matches, do not return anything
    return ''; // Returns an empty string when no case matches
}

 

 

 if the area field is 'ti' and if the system field is 'app' what if the service_typer field is any of: malntenance_ti, installation_ti, configuration_ti, customizetlon_ti, the queue value must be app_n1
Captura de tela 2024-05-06 163001.png

 

11 REPLIES 11

Bert_c1
Kilo Patron

Seems 'queue' is a choice field, in that case you need to verify 'app_n1' is a valid value. You can also an "alert('determineQueue is returning app_n1');" inside the 'if' statement to see if the condition passes.  Add "alert('area = ' + area);" lines to verify the values used in the if condition.

I didn't understand how to do this, and now I have another question, I created the script using Studio's ClientScript, this script would be using the Client or Flow?

Try the following in your code, as you test, you will see the results of the debug:

 

// Client Script to direct a ticket to a queue based on the fields filled in the catalog tree
function onSubmit() {
    var area = g_form.getValue('area');
    var system = g_form.getValue('system');
    var serviceType = g_form.getValue('service_type');
    
    // Determine the queue based on the field values
    var queueValue = determineQueue(area, system, serviceType);
    
    // Update the 'Queue' field with the correct value
    g_form.setValue('queue', queueValue);
	alert("Set queue = " + queueValue);
}

// Function to determine the queue value based on the field values
function determineQueue(area, system, serviceType) {
    // If the area is TI, the system is "app", and the service type meets the criteria
	alert('Checking queue value: area = ' + area + ', system = ' + system + ', serviceType = ' + serviceType);
	var cond = area === 'ti' && system === 'app' &&
        (serviceType === 'maintenance_ti' || serviceType === 'installation_ti' ||
         serviceType === 'configuration_ti' || serviceType === 'customization_ti');
	alert('Checking queue value: condition = ' + cond);
		 
    if (area === 'ti' && system === 'app' &&
        (serviceType === 'maintenance_ti' || serviceType === 'installation_ti' ||
         serviceType === 'configuration_ti' || serviceType === 'customization_ti')) {
			 alert('Checking queue value: returning app_nl');
        return 'app_n1'; // Queue value for app_n1
    }
    
    // If no case matches, do not return anything
    return ''; // Returns an empty string when no case matches
}

It shows alerts about what is happening, but when I finish creating the ticket and go to the support view, the queue value does not change and remains NONE

Check for ACLs, dictionary overrides, and/or business rules that prevent updating the 'queue' field.