replace one word in short description field on change other field value by client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 05:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 10:19 AM
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 10:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 12:28 AM
Thanks for the help.
Please find the screenshot for the requirement.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 12:50 AM
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.