How to populate mrvs variable from other catalog field

Wirasat
Tera Guru

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.

2 ACCEPTED SOLUTIONS

Shivalika
Mega Sage

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

View solution in original post

Brad Bowman
Kilo Patron
Kilo Patron

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'));
    }
}

View solution in original post

4 REPLIES 4

Shivalika
Mega Sage

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

Brad Bowman
Kilo Patron
Kilo Patron

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'));
    }
}

Thanks Brad. It worked perfectly.

You are welcome!