Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need help in client script

nameisnani
Mega Sage

Hi Team 

 

can any one please help me , in this request 

Based on the type of request ,  Infrasturure request should populate .

 

can any one please provide me script for this .

 

nameisnani_1-1721618990080.png

 

nameisnani_0-1721618948635.png

 

12 REPLIES 12

hi @nameisnani ,

please correct your code you need to give

g_form.removeOption('infrastruture',shared_floder')

g_form.removeOption('infrastruture',storage_backup')

g_form.removeOption('infrastruture',patch_management);

 

//like this you need to give one by one for each choice for removing and adding

g_form.addOption('infrastucture',"backend value', ' NAME OF THE CHOICE')//These these are for one choice

Community Alums
Not applicable

Hello @nameisnani 

 

Could you please try the below sample script for onchange catalog client script:

 

(function() {
// Define the mapping between "Type of Request" and "Infrastructure Request"
var typeToInfrastructureMapping = {
"Network": "Network Setup",
"Hardware": "Hardware Installation",
"Software": "Software Installation",
"Security": "Security Configuration"
};

// Get the value of the "Type of Request" field
g_form.getControl('type_of_request').onchange = function() {
var typeOfRequest = g_form.getValue('type_of_request');

// Check if the value exists in the mapping
if (typeToInfrastructureMapping[typeOfRequest]) {
// Set the "Infrastructure Request" field value based on the mapping
g_form.setValue('infrastructure_request', typeToInfrastructureMapping[typeOfRequest]);
} else {
// Clear the "Infrastructure Request" field if no match is found
g_form.setValue('infrastructure_request', '');
}
};
})();

Priya Biradar
Tera Contributor

Hi @nameisnani 

Please use this client script

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var typeReq = g_form.getValue('type_of_request');


    if (typeReq == 'aws') {
        g_form.clearOptions('infrastructure_request');

        g_form.addOption('infrastructure_request', 'none1', 'None');
        g_form.addOption('infrastructure_request', 'request_for_information1', 'Request for Information');
        g_form.addOption('infrastructure_request', 'audit_enquiries1', 'Audit Enquiries');
        g_form.addOption('infrastructure_request', 'data_extract1', 'Data Extract');
        g_form.addOption('infrastructure_request', 'infrastructure_design_enquiries1', 'Infrastructure Design Enquiries');
        g_form.addOption('infrastructure_request', 'shared_folder_access1', 'Shared Folder access');
        g_form.addOption('infrastructure_request', 'storage_and_backup1', 'Storage & Backup');
        g_form.addOption('infrastructure_request', 'patch_management1', 'Patch Management');
    } else if (typeReq == 'kyndryl_mainframe') {
        g_form.clearOptions('infrastructure_request');

        g_form.addOption('infrastructure_request', 'none', 'None');
        g_form.addOption('infrastructure_request', 'request_for_information', 'Request for Information');
        g_form.addOption('infrastructure_request', 'audit_enquiries', 'Audit Enquiries');
        g_form.addOption('infrastructure_request', 'data_extract', 'Data Extract');
        g_form.addOption('infrastructure_request', 'infrastructure_design_enquiries', 'Infrastructure Design Enquiries');
        // g_form.clearOptions('infrastructure_request');
    } else {
        g_form.clearOptions('infrastructure_request');
    }
}