- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 07:12 AM
I am trying to populate some MRVS variables automatically when it is opened using the 'Add' button. These values should be populated from the service catalog variable. For example, there is a variable in the catalog called 'project_code,' and a variable in the MRVS called 'project_id.' The requirement is to automatically populate the 'project_id' value when the MRVS is opened using the 'Add' button.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 08:58 AM
Hello @Wirasat
Please create "On Change" client script utilising the method "getLastRowIndex()". This will ensure that it runs even when add button is clicked, something like below -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return; // Do nothing if the field is just loading or empty
}
var projectCode = g_form.getValue('project_code'); // Get project_code from main catalog form
var newRowIndex = g_form.getLastRowIndex(); // Get the last added row index in MRVS
if (projectCode && newRowIndex >= 0) { // Ensure a valid row exists
g_form.setValue('mrvs_project_id', projectCode, newRowIndex)
;
}
}
Kindly mark my answer as helpful and accept solution if it helped you in anyway,
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 09:31 AM
You can use an onLoad Catalog Client Script that applies to the MRVS, not the Catalog Item. This will run when adding a new row, or editing existing rows, so include a line to check if the variable is already populated before overwriting it.
function onLoad() {
if (g_form.getValue('project_id') == '') {
g_form.setValue('project_id', g_service_catalog.parent.getValue('project_code'));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 08:58 AM
Hello @Wirasat
Please create "On Change" client script utilising the method "getLastRowIndex()". This will ensure that it runs even when add button is clicked, something like below -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return; // Do nothing if the field is just loading or empty
}
var projectCode = g_form.getValue('project_code'); // Get project_code from main catalog form
var newRowIndex = g_form.getLastRowIndex(); // Get the last added row index in MRVS
if (projectCode && newRowIndex >= 0) { // Ensure a valid row exists
g_form.setValue('mrvs_project_id', projectCode, newRowIndex)
;
}
}
Kindly mark my answer as helpful and accept solution if it helped you in anyway,
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 09:31 AM
You can use an onLoad Catalog Client Script that applies to the MRVS, not the Catalog Item. This will run when adding a new row, or editing existing rows, so include a line to check if the variable is already populated before overwriting it.
function onLoad() {
if (g_form.getValue('project_id') == '') {
g_form.setValue('project_id', g_service_catalog.parent.getValue('project_code'));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 10:35 AM
Thanks Brad. It worked perfectly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 12:34 PM
You are welcome!