- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi All ,
I have catalog item i am using varible set under it i have multi row variable set in that i have one field called test which is a single line text . before submitting form if i have any spaces before it should clear . how do i do .
var str = g_form.getValue('variable_1'); var wsr = str.trim(); g_form.setValue('variable_1',wsr );
This is the one i used
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Try on some onChange script first
Thanks,
Bhimashankar H
-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hello @Rajeevreddy ,
You won't be able set like that, it is not simple getting the values from MVRS and setting.
MVRS values are accessed as a JSON string. like a array.
function onSubmit() {
var raw = g_form.getValue(mrvsName);
if (!raw) return true;
var rows = JSON.parse(raw); // MRVS returns JSON array of row objects
var changed = false;
for (var i = 0; i < rows.length; i++) {
if (rows[i].hasOwnProperty('test')) {
var v = rows[i]['test'];
if (typeof v === 'string') {
var trimmed = v.trim(); // removes leading/trailing spaces
if (trimmed !== v) {
rows[i]['test'] = trimmed;
changed = true;
}
}
}
}
if (changed) {
g_form.setValue(mrvsName, JSON.stringify(rows));
}
return true;
}
You can use above code to trim the "test" field in MVRS.
Thanks,
Bhimashankar H
-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi Bhima , Its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hey @Rajeevreddy ,
It is working code; I made simple for you. Try it out.
function onSubmit() {
var raw = g_form.getValue(mrvsName);
if (!raw) return true;
var rows = JSON.parse(raw); // MRVS returns JSON array of row objects
for (var i = 0; i < rows.length; i++) {
var v = rows[i]['test'];
var trimmed = v.trim(); // removes leading/trailing spaces
rows[i]['test'] = trimmed;
}
g_form.setValue(mrvsName, JSON.stringify(rows));
return true;
}
I would suggest first write above code in any other field on change script. Ensure that you first filled the MVRS then change the other field. then this code will execute. Once it is executed then again click on pencil icon on this MVRS then check if spaces are removed or not.
I checked it on my PDI, it is working. If you observe keenly, it won't show the space when you look on form but when you open that row on MVRS then you will see if this code is removed the spaces or not.
Thanks,
Bhimashankar H
-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi Bhima , Did i miss anything or i am referencing it wrongly ?