Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need help on getting Variable name from MRVS

shaik_irfan
Tera Guru

Hi,

I have a MRVS when i called that i get the variable values in JSON format but i get the backend variable name not Question

 

How to get the question and instead of variable name

 

in the catalog client script if i try using 

alert(g_form.getValue('mrvs_name'));

 

In server side

gs.info(current.variables.mrvs_name); //from workflow 

 

I get the same output in JSON format

 

 

 

Can anyone please help me how to display the questions ?

1 ACCEPTED SOLUTION

If hardcoding is OK, following script will replace the name with the question. Pass strMrvs to script include.

    var columnNames = { // names/question pair of columns in mrvs
        'column1': 'Column 1',
        'column2': 'Column 2'
    };
    var mrvsObj = JSON.parse(g_form.getValue('mrvs'));

    for (var i = 0; i < mrvsObj.length; i++) {
        for (var key in columnNames) {
            mrvsObj[i][columnNames[key]] = mrvsObj[i][key];
            delete mrvsObj[i][key];
        }
    }
    var strMrvs = JSON.stringify(mrvsObj);
    alert(strMrvs);

View solution in original post

13 REPLIES 13

@Ankur Bawiskar 

 

It is not working 😞

 

I have a the MRVS when i get the value i am getting in JSON object

If hardcoding is OK, following script will replace the name with the question. Pass strMrvs to script include.

    var columnNames = { // names/question pair of columns in mrvs
        'column1': 'Column 1',
        'column2': 'Column 2'
    };
    var mrvsObj = JSON.parse(g_form.getValue('mrvs'));

    for (var i = 0; i < mrvsObj.length; i++) {
        for (var key in columnNames) {
            mrvsObj[i][columnNames[key]] = mrvsObj[i][key];
            delete mrvsObj[i][key];
        }
    }
    var strMrvs = JSON.stringify(mrvsObj);
    alert(strMrvs);

@hozawa 

 

It is not working 😞

Maybe, I'm misunderstanding the question.

Provide me a set of column names and labels that's being used in mrvs as well as the expected json.

This is what I get.

find_real_file.png

After change

find_real_file.png

Mark Roethof
Tera Patron
Tera Patron

Hi there,

To get the label of a variable within your variable set, you could use something like:

g_form.getLabelOf('variable_name')

(= tested, works)

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn