Add a second variable with period

Community Alums
Not applicable

Hi,

I currently have a requirement where, I have variables Prefix, CI Name, Description, and "Security Kafka Topic Name". The value of the "Security Kafka Topic Name" will be a value of these variables separated by "_". The code here is working correctly. 

 

client.PNG

 

 

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

    var topic = g_form.getValue("topic_name1");

    var contains_space = "";
    var more_chars = "";
    var regex = new RegExp("^[a-zA-Z0-9]*$");


    if (newValue.length > 18) {
        alert("More than 18 chacters entered.");
        g_form.setValue('description', " ");

    } else if (!regex.test(newValue)) {
        var no_space = newValue.replace(" ", "_");
        g_form.setValue('description', no_space);
        g_form.setValue('topic', no_space);
        contains_space = "true";
    }

}

 

 

Now I am asked to add another variable on the form "Data Lake Admins Kafka Topic Name". This variable will hold the same scenario as above, but underscore will be replaced with ".". This is where I am unable to do it. Kindly help with the code adjustment or at least the idea of how to do it.

 

client_1.PNG

In the above picture, I am getting the "." because, I am using the client script.

 

client_2.PNG

 

 

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

        var prefix = g_form.getValue('prefix');
        var ci_code = g_form.getValue('ci_code1');
        var description = g_form.getValue('description');
        g_form.setValue('data_lake_admins_kafka_topic_name', prefix + "." + ci_code + "." + newValue.toLowerCase());
    }

 

 

Now I am asked to add another variable on the form "Data Lake Admins Kafka Topic Name". This variable will hold the same scenario as above, but underscore will be replaced with ".". This is where I am unable to do it. Kindly help with the code adjustment or at least the idea of how to do it.

 

Regards

Suman P.

 

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

Please try below script:

var prefix = g_form.getValue('prefix');
        var ci_code = g_form.getValue('ci_code1');
        var description = g_form.getValue('description');
        g_form.setValue('data_lake_admins_kafka_topic_name', prefix + "." + ci_code + "." + newValue.replaceAll("_", "."));
    }
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

1 REPLY 1

Anil Lande
Kilo Patron

Hi,

Please try below script:

var prefix = g_form.getValue('prefix');
        var ci_code = g_form.getValue('ci_code1');
        var description = g_form.getValue('description');
        g_form.setValue('data_lake_admins_kafka_topic_name', prefix + "." + ci_code + "." + newValue.replaceAll("_", "."));
    }
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande