- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 03:08 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 03:32 AM - edited 04-25-2024 03:33 AM
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 03:32 AM - edited 04-25-2024 03:33 AM
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 04:21 AM
Short description not starts with "y_" . short decription contains any where "y_".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 04:00 AM
Hi @AJAYKUMAR G,
So my response is not lost in the thread.
This is easily achieved with an adapted onChange Client Script to look for a string of 'y_'.
See the below-updated 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 containsVal = valToComapre.indexOf('y_');
if(containsVal > -1){
var result = newValue.slice(containsVal).trim().split(' ')[0];
g_form.setValue('your_field_name', result);
}
}