Reading variable name from service catalog

Sri29
Tera Contributor

I have a requirement where I need to show the (RITM) item variable key, value on a notification page. 

 

I looked into 2 tables, 'sc_req_item', 'sc_item_option_mtom'. I can filter required RITM and lookup the variable using fields "Dependent Item.Question.Display name", "Dependent Item.Question.Value" on UI. However, when I tried using basic script, I don't see variables returned.

==

var itemOption = new GlideRecord('sc_item_option_mtom');
itemOption.get('db3d44951b8e7550ac210fa5624bcb3c');

for (var key in itemOption ) {
gs.info('Attribute Name : '+key +' Value : '+itemOption[key]);
}

==

How do I query these values from my script (trying with background script).? I could be missing some basic thing.

 

Thanks for help!

1 ACCEPTED SOLUTION

@Sri29 :I just tried the same script in BG and below is the output for sample RITM.

 

sainathnekkanti_0-1703616499580.png

 

var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID('7f2fd6ed97c62110aa7c50081153aff4'); // RITM Sys ID
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            gs.log(vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue());
        }
    }

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

View solution in original post

3 REPLIES 3

Sainath N
Mega Sage
Mega Sage

@Sri29 : Here is the email script that can be used in notification to get the variable information.

 

function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.request_item.sys_id);
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            template.print(vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue());
            template.print("\n");
        }
    }

})(current, template, email, email_action, event);

 

I answered the similar question in another thread. Below is the link for your reference.

https://www.servicenow.com/community/virtual-agent-forum/adding-line-breaks-between-variables-in-ema...

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

 

@Sri29 :I just tried the same script in BG and below is the output for sample RITM.

 

sainathnekkanti_0-1703616499580.png

 

var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID('7f2fd6ed97c62110aa7c50081153aff4'); // RITM Sys ID
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            gs.log(vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue());
        }
    }

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,

Do you have multi row variable set as well?

You can go through the below article for getting all types of variables.

https://www.servicenow.com/community/developer-blog/reusable-custom-flow-action-to-get-all-the-catal...

 

 

 

 

 

 


Thanks and Regards,

Saurabh Gupta