Displaying the current Value of a variable

Bryan Campbell
Giga Expert

Looking for some assistance with a Script that doesn't appear to be working.   What we are trying to do is display the current value of a select box variable in the short description of a task that is generated from a request as well as display the name of the person it is requested for.   The end result is that the short description of the task would read the selection that was made from the drop down along with the client's name i.e. "Fulfill SAS Report for John Doe"

var perm = current.request.requested_for.name;

var tempvendor = current.request.u_temp_vendor_name;

var fulfill = 'Fulfill ' + current.variables.type_report + 'Report for ';

if (perm.nil()){

        task.short_description = fulfill + tempvendor;

} else {

        task.short_description = fulfill + perm;

1 ACCEPTED SOLUTION

Thanks Berny.   Sorry I didn't reply sooner but I was away on vacation after the 19th.   I actually got this to work by making a minor change.   I needed to use a double apostrophe instead of a single on the below line and now the code works as expected.   We're still on Dublin, no sure if that makes a difference.



var fulfill = "Fulfill " + current.variables.type_report + " Report for ";



Thanks again.


View solution in original post

14 REPLIES 14

Hi Bryan,



Try this.


var fulfill = 'Fulfill ' + current.variables.type_report.getDisplayValue() + 'Report for ';


Thank you Pradeep unfortunately that didn't seem to work.



variable_2.jpg


This suggestion to append "getDisplayValue()" to the end of the string resolved my similar issue! It's strange since it seemed it was working fine before that and stopped working after some other changes were made on the form. Thanks.


Scott Simon
ServiceNow Employee
ServiceNow Employee

Hello, Bryan:


Are you using a workflow or business rule?


If you are using a workflow, you need to add the type_report field on the "Variables on Task Form" from available to selected:


Screen Shot 2015-06-20 at 2.22.34 PM.JPG


Try to run the workflow after this change.


If this doesn't work:


If you are in a workflow, add this message to the script log:


gs.log('value ' + current.variables.type_report);


gs.log('label ' + current.variables.type_report.getDisplayValue());



Check the script log: The value log should return a value.   the label log should return the label field.



If you are using a business rule, can you add this line before var fulfill?


alert(current.variables.type_report);


You should get a value popup message.


alert(current.variables.type_report.getDisplayValue());


You should get a label popup message.



Let me know how you make out.



Scott


bernyalvarado
Mega Sage

Hi Bryan, I just tried your code in my Developer instance and in worked great with one small change, which was to end the final else with a curly bracket. Here is the code that it worked for me.


var perm = current.request.requested_for.name;


var tempvendor = current.request.u_temp_vendor_name;


var fulfill = 'Fulfill ' + current.variables.type_report + 'Report for ';



if (perm.nil()){


        task.short_description = fulfill + tempvendor;


} else {


        task.short_description = fulfill + perm;


}



Thanks,


Berny