populate field with manual value push from script based on condition met on other catalog form

amitesh2
Tera Contributor

i have to catalog one is customer on boarding other env on boarding .

customer onboarding have field a,b,c yes/no  we cane give based on that their is field on env onboarding has to populate with value given in script .

4 REPLIES 4

Nilesh Pol
Tera Guru

@amitesh2 

You can make a use of catalog client script + script include.

imaginary ccs:

 

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

// Get the current values of fields a, b, and c
var fieldA = g_form.getValue('a'); // Assuming 'a', 'b', 'c' are the field names
var fieldB = g_form.getValue('b');
var fieldC = g_form.getValue('c');
var environmentFieldValue = '';

if (fieldA == 'Yes' && fieldB == 'Yes' && fieldC == 'Yes') {
environmentFieldValue = 'Option 1'; // Populate with a specific value if all are Yes
} else if (fieldA == 'Yes' && fieldB == 'No' && fieldC == 'Yes') {
environmentFieldValue = 'Option 2'; 
} else if (fieldA == 'No' && fieldB == 'Yes' && fieldC == 'No') {
environmentFieldValue = 'Option 3'; 
} else {
environmentFieldValue = 'Default'; 
}

var ga = new GlideAjax('UpdateEnvironmentOnboarding');
ga.addParam('sys_id', g_form.getUniqueValue());
ga.addParam('environmentField', environmentFieldValue); 
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
});
}

Script include

var UpdateEnvironmentOnboarding = Class.create();
UpdateEnvironmentOnboarding.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateEnvironmentField: function() {
var customerOnboardingSysId = this.getParameter('sys_id'); 
var environmentFieldValue = this.getParameter('environmentField'); 
var gr = new GlideRecord('sc_req_item'); 
if (gr.get(customerOnboardingSysId)) {
gr.environment_field = environmentFieldValue; 
gr.update(); 
}
return 'Success'; 
}
});

if any one from a or b or  c is yes then we have to push value LIQ

 

@amitesh2 You can Add || (OR) condition according your requirement.

Ankur Bawiskar
Tera Patron
Tera Patron

@amitesh2 

so what's your form and how it looks and what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader