- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 10:42 AM
We have a Service Catalog to request various Telecom Requests. I am building a Workflow, based on the Requested Item that is created from the Request. I am trying to add an IF Action that checks to see if the request was for some special software (in which case, I will then use Create Task to create a task fro the software installation).
So, on the Service Catalog, the variable for the requested item is named u_request_type, and it is a Reference Field to the table which contains the various request selections. The code for my IF action looks like this:
answer = ifScript();
var requestType = current.variables.u_request_type;
function ifScript() {
if (requestType == 'Special Software') {
return 'yes';
} else {
return 'no';
}
}
Needless to say, it doesn't work. I think it is because the u_request_type is a reference field to another table.
So, how do I get the displayed value for this field? Do I need to dot-walk, or somehow use GetDisplayName?
Not sure exactly what the code for that needs to look like.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 01:51 PM
My and Joe, i completely over looked your ifScript function . Your script looks good to me. Lets try one last thing here , for the if
if(current.variables.u_request_type.service.service_name.indexOf('Avaya Software') > -1){
return 'yes';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 11:02 AM
You can easily get the display value of something using the getDisplayValue() function:
So this line:
var requestType = current.variables.u_request_type;
Becomes:
var requestType = current.variables.u_request_type.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 11:10 AM
Hi Michael,
I have had issues with using getDisplayValue on variables. Does the behavior differ between fields and variables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 11:11 AM
I had tried that earlier, but it was not working (perhaps because the variable was set before the function (see my previous reply to harishkumar).
I wanted to see if it would work in a background script, so I tried both methods like this:
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number','RITM0010549')
gr.query();
while(gr.next()){
gs.print(gr.variables.u_request_type.service.service_name);
gs.print(gr.variables.u_request_type.getDisplayValue);
}
and this is what was returned:
*** Script: Avaya Software
*** Script: function getDisplayValue() {
[native code, arity=1]
}
So I don't know that it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 11:15 AM
You forgot the parentheses on getDisplayValue()
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number','RITM0010549')
gr.query();
while(gr.next()){
gs.print(gr.variables.u_request_type.service.service_name);
gs.print(gr.variables.u_request_type.getDisplayValue());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2017 11:25 AM
OK, I added them in, and then that did return the correct value of 'Avaya Software'.
But when I tried to put it back into my Workflow script, it did not work. Here is what I tried:
answer = ifScript();
var requestType = current.variables.u_request_type.getDisplayValue();
function ifScript() {
if (requestType == 'Avaya Software') {
return 'yes';
} else {
return 'no';
}
}
Do we need to use Glide Records in this code?