Get current variables value by setting variable name from a table

raj_singh
Giga Contributor

Requirement - Populate Short description based in choice selected for a variable.

I am configuring a workflow which can be utilize by many SR, for that I have created a table from where I am fetching the required data and setting it for task details.

Few SR's task have short description based on selected request type. Which can be achieved by

task.short_description = "xyxyxyxyxyxy" + current.variables.req_type;

Now for few SR, dependent variable name is other than req_type;

So I found a solution that I will pass the variable name from 'abcabc' table and based on this variable name, I will set Short description.

task.short_description = "xyxyxyxyxyxy" + current.variables.Dynamic_Variable_from_abcabc_table;

 

Below script is not working to setting the task short description.

Let me know how this will work or any workaround for it.

 

var config = new GlideRecord('abcabc');
config.addQuery('u_req','TEST SR');
config.query();
while(config.next()){
task.short_description = "xyxyxyxyxyxy" + current.variables.config.u_variable_name;

}

@Chuck Tomasi @Pradeep Sharma @Ankur Bawiskar @Brad Tilton @Mark Roethof @Michael Fry 

1 ACCEPTED SOLUTION

Hi

I think I got yout requirement. What I prepared for you, is a small script, which shows, how you could to dynamically, about what you want to do:

var gr = new GlideRecord('sc_req_item');

gr.addQuery('number', 'RITM0010032');
gr.query();

if (gr.next()) {
   gs.info('got it: ' + gr.number);
   gs.info(gr.variables.getElements());
   gs.info(gr.variables.what_county.getValue());

   var current = gr;
   var useThisVariableName   = 'what_country';
   var theValueToSet = '';

    var variables = current.variables.getElements(); 
    for (var i=0;i<variables.length;i++) {
        var question = variables[i].getQuestion(); 
        if (question.name == useThisVariableName) {
            theValueToSet = question.getValue();
        }
//      gs.addInfoMessage(question.name + " / " + question.getLabel() + ":" + question.getValue()); 
    } 

    gs.info('The value of the variable called ' + useThisVariableName + ' is ' + theValueToSet);

}

Take this as a starting point to get variable values for having the NAME of the variable to use, in a different variable.

 

Let me know if that answers your question and mark my answer as correct helpful.

Thanks & BR

Dirk

 

 

 

View solution in original post

14 REPLIES 14

DirkRedeker
Mega Sage

Hi

I do not get your requirement details. May you give a bit more details about your requirement?

BR

Dirk

I am configuring a workflow which can be utilize by many SR, for that I have created a table from where I am fetching the required data and setting it for task details.

Few SR's task have short description based on selected request type. Which can be achieved by

task.short_description = "xyxyxyxyxyxy" + current.variables.req_type;

Now for few SR, dependent variable name is other than req_type;

So I found a solution that I will pass the variable name from 'abcabc' table and based on this variable name, I will set Short description.

task.short_description = "xyxyxyxyxyxy" + current.variables.Dynamic_Variable_from_abcabc_table;

 

I hope you will have some clarification on the requirement.

 

 

Hi

I think I got yout requirement. What I prepared for you, is a small script, which shows, how you could to dynamically, about what you want to do:

var gr = new GlideRecord('sc_req_item');

gr.addQuery('number', 'RITM0010032');
gr.query();

if (gr.next()) {
   gs.info('got it: ' + gr.number);
   gs.info(gr.variables.getElements());
   gs.info(gr.variables.what_county.getValue());

   var current = gr;
   var useThisVariableName   = 'what_country';
   var theValueToSet = '';

    var variables = current.variables.getElements(); 
    for (var i=0;i<variables.length;i++) {
        var question = variables[i].getQuestion(); 
        if (question.name == useThisVariableName) {
            theValueToSet = question.getValue();
        }
//      gs.addInfoMessage(question.name + " / " + question.getLabel() + ":" + question.getValue()); 
    } 

    gs.info('The value of the variable called ' + useThisVariableName + ' is ' + theValueToSet);

}

Take this as a starting point to get variable values for having the NAME of the variable to use, in a different variable.

 

Let me know if that answers your question and mark my answer as correct helpful.

Thanks & BR

Dirk

 

 

 

Thanks Dirk. I will check this and get back.