The CreatorCon Call for Content is officially open! Get started here.

How populate string if short Description contains particular value then value populate anothe field

AJAYKUMAR G
Tera Contributor

If short Description : Registered as y_6778 journey 

Field name : Key (string)

 

My question is I need populate the "y_6778" value in key field. How to approach.

1 ACCEPTED SOLUTION

Sohail Khilji
Kilo Patron

Hi @AJAYKUMAR G ,

 

As you have not mentioned that when do you need this to take place , i assume that you need it when the record is updated or create / if its on change of field on form then you can use onchange client scipt or if on insert or update you need to use business rule.

 

for client script :

 

function onChangeShortDescription(control, oldValue, newValue, isLoading) {
  
    if (newValue && newValue.startsWith("y_")) {
        var match = newValue.match(/y_\d+/);
        if (match) {
            var extractedValue = match[0];
            g_form.setValue('key', extractedValue);
        }
    }
}

 

if its business rule :

 

(function executeRule(current, previous /*null when async*/) {
   
    if (current.short_description.changes() && current.short_description.startsWith("y_")) {
 
        var match = current.short_description.match(/y_\d+/);
        if (match) {
            var extractedValue = match[0];
            // Set the extracted value into the key field
            current.key = extractedValue;
        }
    }

})(current, previous);

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

View solution in original post

7 REPLIES 7

Robbie
Kilo Patron
Kilo Patron

Hi @AJAYKUMAR G,

 

This is easily achieved with an onChange Client Script.

See the below script and screenshot for guidance.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

 

 

 

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

   var valToComapre = newValue;
   var matchFound = valToComapre.match('y_6778');
   if(matchFound){
	g_form.setValue('your_field_name', matchFound);
   }
   
}

 

 

 Screenshot 2024-04-25 at 11.18.55.png

Not exact value I have given .. it like starts y_ 

Hi @AJAYKUMAR G,

 

I thought it was too specific and literal... 

 

Tweak the onChange script to the below:

 

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

   var valToComapre = newValue;
   var containsVal = valToComapre.indexOf('y_');
   if(containsVal > -1){
		var result = newValue.slice(containsVal).trim().split(' ')[0];
		g_form.setValue('your_field_name', result);
   }
   
}

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

 

Here you mentioned as start with y_  > 🙂


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect