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

Hi

Do you have any update on this?

Did my answer solve your issue?

Just let me know and mark my answer as correct & helpful

BR

Dirk

Thanks Drik for the solution. It is working and solved my issue.

Jaspal Singh
Mega Patron
Mega Patron

Hi Raj,

 

For your statement,

This variable name should be dynamic so that we will change the variable value in abcabc table and task's short description will change accordingly.

You need to have Business rule in place that would update it for the variables already submitted.

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.

 

 

Thanks for the update Raj. Yes, it helps understand.

So, what is the issue now. If the above script not working?