A Variable should have periods but the description variable should have underscores

Community Alums
Not applicable

Hi,

I have a variable "Kafka Topic Name" with backend name "topic_name1". We get the value of "topic_name1" by using the below client script. Here in this variable the separator for prefix, etc. is a "."

 

topic name.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');
    // 	if(description.length >40)
    // 		{
    // 			var sub = newValue.substring(0,40);
    //  			g_form.setValue("description",sub);
    // 			g_form.setValue('topic_name1',prefix+"."+ci_code+"."+sub);
    // 		}

    g_form.setValue('topic_name1', prefix + "." + ci_code + "." + newValue.toLowerCase());
  //  g_form.setValue('data_lake_admins_kafka_topic_name', prefix + "_" + ci_code + "_" + newValue.replaceAll(".", "_"));

    //Type appropriate comment here, and begin script below

}

 

kafka.PNG

 

There is another variable "Kafka Group Details" with backend name "group_details1". We get the value of this "group_details1" with the following client script.

 

topic_name1.PNG

 

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

	var topic = g_form.getValue('topic_name1');
	var topic1 = g_form.getValue("data_lake_admins_kafka_topic_name");
	var approver_sys = g_form.getValue('account_owner_approver');
	
	var referenceHelperAjax = new GlideAjax('global.regionsITSMclientHelper');
	referenceHelperAjax.addParam('sysparm_name','getRecordFieldValues');
	referenceHelperAjax.addParam('sysparm_table', 'sys_user');
	referenceHelperAjax.addParam('sysparm_rec_id', approver_sys);
	referenceHelperAjax.addParam('sysparm_fields', 'name');
	referenceHelperAjax.getXML(processAjax);

	function processAjax(response) {
		
		
		var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
		
		var approver = answer.name.value;	
	var str = "Topic Name : "+topic1+"\n"+"Account Owner / Approver : "+approver+"\n"+"Group Details : "+"\n\n"+      
		
		"Environment : Development"+"\n"+"Group Name : kafka_grp_"+topic+"_r_d"+"\n"+"Description : Controls read only access to the Kafka topic - "+topic+" - through Ranger in the Development Kafka environment."+"\n\n"+
		
		"Environment : Disaster Recovery"+"\n"+"Group Name : kafka_grp_"+topic+"_r_dr"+"\n"+"Description : Controls read only access to the Kafka topic - "+topic+" - through Ranger in the Disaster Recovery Kafka environment."+"\n\n"+
		
		"Environment : Production"+"\n"+"Group Name : kafka_grp_"+topic+"_r_p"+"\n"+"Description : Controls read only access to the Kafka topic - "+topic+" - through Ranger in the Production Kafka environment."+"\n\n"+
		
		"Environment : Test"+"\n"+"Group Name : kafka_grp_"+topic+"_r_t"+"\n"+"Description : Controls read only access to the Kafka topic - "+topic+" - through Ranger in the Test Kafka environment."+"\n\n"+
		
		"Environment : Development"+"\n"+"Group Name : kafka_grp_"+topic+"_rwx_d"+"\n"+"Description : Controls read, write and execute access to the Kafka topic - "+topic+" - through Ranger in the Development Kafka environment."+"\n\n"+
		
		"Environment : Disaster Recovery"+"\n"+"Group Name : kafka_grp_"+topic+"_rwx_dr"+"\n"+"Description : Controls read, write and execute access to the Kafka topic - "+topic+" - through Ranger in the Disaster Recovery Kafka environment."+"\n\n"+
		
		"Environment : Production"+"\n"+"Group Name : kafka_grp_"+topic+"_rwx_p"+"\n"+"Description : Controls read, write and execute access to the Kafka topic - "+topic+" - through Ranger in the Production Kafka environment."+"\n\n"+
		
		"Environment : Test"+"\n"+"Group Name : kafka_grp_"+topic+"_rwx_t"+"\n"+"Description : Controls read, write and execute access to the Kafka topic - "+topic+" - through Ranger in the Test Kafka environment."+"\n\n";
		
		
		
		
		
	g_form.setValue('group_details1',str);
		
		
		
   //Type appropriate comment here, and begin script below
   
}
}

 

group.PNG

 

The requirement is, the highlighted portion (Kafka Topic Name) should have a separator of "_" instead of "." for "Kafka Group Details". How can I achieve this? Kindly help.

 

Regards

Suman P.

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If you only need to change this in the second onChange script, just add a line before the var str like

topic = topic.replace(".", "_");

 

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

If you only need to change this in the second onChange script, just add a line before the var str like

topic = topic.replace(".", "_");

 

Community Alums
Not applicable

Hello @Community Alums ,

 

 

To confirm, you're looking to extract the value "elt-wm55-s.u.m.a.n" from the 'topic_name1' field and place it within the 'group_details1' field. Please correct me if my understanding is incorrect.

Here's the proposed solution:

  1. Add a new field, 'topic_name2': This field will store the hyphen-separated value of 'prefix', 'ci_code', and 'description'. You might want to hide this field from the form, which can be achieved using the onLoad client script.

  2. Modify the 'populate topic - description' client script: Update the script to the following:

    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');
        // 	if(description.length >40)
        // 		{
        // 			var sub = newValue.substring(0,40);
        //  			g_form.setValue("description",sub);
        // 			g_form.setValue('topic_name1',prefix+"."+ci_code+"."+sub);
        // 		}
    
        g_form.setValue('topic_name1', prefix + "." + ci_code + "." + newValue.toLowerCase());
        g_form.setValue('topic_name2', prefix + "-" + ci_code + "-" + newValue.toLowerCase());
        //  g_form.setValue('data_lake_admins_kafka_topic_name', prefix + "_" + ci_code + "_" + newValue.replaceAll(".", "_"));
    }​
    
  3. Update the 'populate group description - topic' script: Modify the script as provided below:
    function onChange(control, oldValue, newValue, isLoading) {
        if (isLoading || newValue == '') {
            return;
        }
    
        var topic = g_form.getValue('topic_name2');
        var topic1 = g_form.getValue("data_lake_admins_kafka_topic_name");
        var approver_sys = g_form.getValue('account_owner_approver');
    
        var referenceHelperAjax = new GlideAjax('global.regionsITSMclientHelper');
        referenceHelperAjax.addParam('sysparm_name', 'getRecordFieldValues');
        referenceHelperAjax.addParam('sysparm_table', 'sys_user');
        referenceHelperAjax.addParam('sysparm_rec_id', approver_sys);
        referenceHelperAjax.addParam('sysparm_fields', 'name');
        referenceHelperAjax.getXML(processAjax);
    
        function processAjax(response) {
    
    
            var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
    
            var approver = answer.name.value;
            var str = "Topic Name : " + topic1 + "\n" + "Account Owner / Approver : " + approver + "\n" + "Group Details : " + "\n\n" +
    
                "Environment : Development" + "\n" + "Group Name : kafka_grp_" + topic + "_r_d" + "\n" + "Description : Controls read only access to the Kafka topic - " + topic + " - through Ranger in the Development Kafka environment." + "\n\n" +
    
                "Environment : Disaster Recovery" + "\n" + "Group Name : kafka_grp_" + topic + "_r_dr" + "\n" + "Description : Controls read only access to the Kafka topic - " + topic + " - through Ranger in the Disaster Recovery Kafka environment." + "\n\n" +
    
                "Environment : Production" + "\n" + "Group Name : kafka_grp_" + topic + "_r_p" + "\n" + "Description : Controls read only access to the Kafka topic - " + topic + " - through Ranger in the Production Kafka environment." + "\n\n" +
    
                "Environment : Test" + "\n" + "Group Name : kafka_grp_" + topic + "_r_t" + "\n" + "Description : Controls read only access to the Kafka topic - " + topic + " - through Ranger in the Test Kafka environment." + "\n\n" +
    
                "Environment : Development" + "\n" + "Group Name : kafka_grp_" + topic + "_rwx_d" + "\n" + "Description : Controls read, write and execute access to the Kafka topic - " + topic + " - through Ranger in the Development Kafka environment." + "\n\n" +
    
                "Environment : Disaster Recovery" + "\n" + "Group Name : kafka_grp_" + topic + "_rwx_dr" + "\n" + "Description : Controls read, write and execute access to the Kafka topic - " + topic + " - through Ranger in the Disaster Recovery Kafka environment." + "\n\n" +
    
                "Environment : Production" + "\n" + "Group Name : kafka_grp_" + topic + "_rwx_p" + "\n" + "Description : Controls read, write and execute access to the Kafka topic - " + topic + " - through Ranger in the Production Kafka environment." + "\n\n" +
    
                "Environment : Test" + "\n" + "Group Name : kafka_grp_" + topic + "_rwx_t" + "\n" + "Description : Controls read, write and execute access to the Kafka topic - " + topic + " - through Ranger in the Test Kafka environment." + "\n\n";
    
            g_form.setValue('group_details1', str);
    
        }
    }​

If you found this helpful, a 'like' is the secret handshake of appreciation! Also, please accept it as the solution, so that others can find the solution quickly!

- Prasad