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

replace one word in short description field on change other field value by client script

vinnus
Tera Contributor

When an Agent updates or changes the System(Choice field) field  in the agents input the Short description  fields need to be updated accordingly. 

We need replace system field value with one of the word in the Short description field value.

8 REPLIES 8

Sohithanjan G
Kilo Sage

Hi @vinnus ,

 

You can have an onChange client script on system field with below script

        var systemValue = g_form.getValue('system_field_id');
        var shortDescription = g_form.getValue('short_description');
        var newShortDescription = shortDescription.replace('word_to_replace', systemValue);
        g_form.setValue('short_description', newShortDescription);

 

Let me know with your screenshot, if you need more on this...

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Aravind2799
Giga Expert

Hey @vinnus 

 

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

  var shortDescField = g_form.getField('short_description_field_id');
  if (shortDescField) {
    var newDesc = shortDescField.getValue();
    var chosenSystem = newValue; // Get the selected value from "System" field

    // Define a mapping between chosen system value and replacement word
    var systemToWordMap = {
      "System Value 1": "Replacement Word 1",
      "System Value 2": "Replacement Word 2",
      // ... Add more mappings as needed
    };

    // Check if chosen system has a corresponding replacement word
    var replacementWord = systemToWordMap[chosenSystem];
    if (replacementWord) {
      // Extract the word to replace from the short description (assuming it's the first word)
      var words = newDesc.split(' ');
      if (words.length > 0) {
        words[0] = replacementWord;
        newDesc = words.join(' ');
      }
      shortDescField.setValue(newDesc);
    }
  }
}

 

Explanation:

  • We define a systemToWordMap object that maps chosen system values to their corresponding replacement words.
  • We retrieve the selected value from the "System" field (newValue).
  • We check if the chosen system has a mapping in the systemToWordMap object.
  • If a mapping exists, we extract the first word from the short description (assuming it's the word to replace).
  • We replace the extracted word with the corresponding replacement word from the mapping.
  • Finally, we set the updated value back to the short description field.

Important Notes:

  • Replace your_system_field_id with the actual ID of the "System" field.
  • Replace short_description_field_id with the ID of the short description field.
  • Modify the systemToWordMap object to include all desired system values and their corresponding replacement words.
  • This script assumes the word to replace is the first word in the short description field. You might need to modify the logic to extract the desired word based on your specific requirements.

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

Regards, 

Aravind Panchanathan

https://www.linkedin.com/in/aravindpanchanathan2799/

Thanks for the help.

Please find the screenshot for the requirement.

vinnus_0-1709886512759.png

 

Task record created from record producer , the short description populated from RP, now we need to relace one of the course present in the short description,  when ever course value updated in user input section. there will be values  like SAP and SAP analytics as courses , here we will get conflict SAP.

Please help me out the solution. 

Thanks 

vinnus
Tera Contributor

Course= u_course

Short description= short_description

And the course value in the short description is Dynamic, the placement word place in the short description will change record to record sometimes will be same place.