If NewValue contains "#" then change it to %23

VIKAS MISHRA
Tera Contributor

We have written one on change client script , on change on field "Account_name".

While filling the request form on portal user can see one field "Account name" and there he can add any value. 

So now if user add any string and that string contanings "#" then my client script should change that # to %23, i and i am hoping that different should be making impact in the line no. 21 and 23. for the varaible odata

Please sugest how to do that.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    g_form.clearOptions('select_technology_for_account');
    var typeOfAction = g_form.getValue('select_type_of_action');
    //var accountName = g_form.getValue('account_name');
    var domain = 'AD Domains(';
    var arr = [];
    var platcodecontains = ['OPSNETX', 'LABLAN', 'URCLAB', 'EMRELAB', 'XOMDMZ', 'CLNLAB', 'LABLAN.LOCAL'];
    setTimeout(function() {
        g_form.addOption('select_technology_for_account', '', '-- None --');
        g_form.showFieldMsg('select_technology_for_account', "Please wait until we finish querying the system");
        g_form.setMandatory('select_technology_for_account', false);
        g_form.setReadOnly('select_technology_for_account', true);
        var ga = new GlideAjax('x_iem_iam.IAM_API_Utils_Ajax');
        ga.addParam('sysparm_name', 'searchPrincipalOdata');
        var odata;
        if (typeOfAction == 'Reset Password') {
            odata = 'PrincipalTypeIsUserID eq true and IsPrimary eq false and (Techcode ne \'SAP/R3\' and Techcode ne \'SAP/HANA\') and UID eq ' + '\'' + newValue + '\'';
        } else {
            odata = 'PrincipalTypeIsUserID eq true and UID eq ' + '\'' + newValue + '\'';
        }
        ga.addParam('sys_param_odata', odata);

        function myfun(item) {
            var s = new Set(item);
            var it = s.values();
            return Array.from(it);
        }
        ga.getXML(function(response) {
            var answer = response.responseXML.documentElement.getAttribute('answer');
			//console.log('vikas' + answer);
            var answer_obj = JSON.parse(answer);
            //alert(answer_obj);
            answer_obj.forEach(function(element) {
                if (element.techcode != 'EMAIL' && element.techcode != 'VPN' && element.techcode != 'ADLDS' && element.techcode != 'AZURE' && element.techcode != 'SAAS' && element.techcode != 'APPLICATN' && element.platcode != 'DRAC' && element.platcode != 'HP' && element.platcode != 'SAP/WAS' && element.platcode != 'XOMRES.CLOUD') {
                    if (element.techcode == 'NT' && !platcodecontains.includes(element.platcode)) {
                        arr.push(element.platcode);
                    } else if (element.techcode == 'NT' && platcodecontains.includes(element.platcode)) {
                        g_form.addOption('select_technology_for_account', element.platcode, element.platcode);
                    } else {
                        if (typeOfAction != 'Unlock Account') {
                            g_form.addOption('select_technology_for_account', element.techcode, element.techcode);
                        }
                    }

                }
            });
            if (typeOfAction == 'Reset Password' || typeOfAction == 'Unlock Account') {
				//alert("New API CALL")
                var ga2 = new GlideAjax('x_iem_iam_iga_2.IAM_API_V2_Utils_Ajax');
                ga2.addParam('sysparm_name', 'searchAccountOdata');
                var odataparam;

                odataparam = 'SourceType in (\'SAP\' ,\'SAP HANA\') and DataSource eq \'IDN\' and Name eq \'' + newValue + '\'';
					console.log(odataparam)
                ga2.addParam('sys_param_odata', odataparam);

                ga2.getXML(function(response) {
                    var resp = response.responseXML.documentElement.getAttribute('answer');
                    var json_value_obj = JSON.parse(resp);
                    //alert(json_value_obj);
                    json_value_obj.forEach(function(element)

                        {
                            if (element.sourcetype != 'EMAIL' && element.sourcetype != 'VPN' && element.sourcetype != 'ADLDS' && element.sourcetype != 'AZURE' && element.sourcetype != 'SAAS' && element.sourcetype != 'APPLICATN' && element.sourcename != 'DRAC' && element.sourcename != 'HP' && element.sourcename != 'SAP/WAS' && element.sourcename != 'XOMRES.CLOUD') {
                                if (element.sourcetype == 'NT' && !platcodecontains.includes(element.sourcename)) {
                                    arr.push(element.sourcename);
                                } else if (element.sourcetype == 'NT' && platcodecontains.includes(element.sourcename)) {
                                    g_form.addOption('select_technology_for_account', element.sourcename, element.sourcename);
                                } else {
                                    var source = element.sourcetype == "SAP" ? "SAP" : element.sourcetype == "SAP HANA" ? "SAP HANA" : element.sourcetype;
                                    console.log(source);
									g_form.addOption('select_technology_for_account', source, source);

                                }

                            }
                        });

                });
            }
            var b = myfun(arr);
           // g_form.addOption('select_technology_for_account', domain + b + ')', domain + b + ')');
			g_form.addOption('select_technology_for_account', platcodecontains.includes(b)? b: domain+ b+')', domain + b + ')');
            g_form.setReadOnly('select_technology_for_account', false);
            g_form.setMandatory('select_technology_for_account', true);
            g_form.hideFieldMsg('select_technology_for_account');
            var len = answer_obj.length;
            if (len == 0)
                g_form.showFieldMsg('select_technology_for_account', 'No data available with this name');
				g_form.hideFieldMsg('select_technology_for_account')

        });
    }, 1000);



    //Type appropriate comment here, and begin script below
}

 

5 REPLIES 5

HI Ankur i just have added the complete requirement above in reply to  Chaitanya question, please help me with the correct answer