how to get display value?

Kiddy1
Tera Contributor

explorenow srinivasthelu Developer Community

var fake=current.u_fake;

var fake2='op'+fake.getDisplayValue();

is this correct?

19 REPLIES 19

thank you so much, it helped me.

"m new to service now , please suggest me the sites for service now script.

 

Once again thanks 🙂

go through the servicenow training portal. that will help you alot. also search the book "Mastring Servicenow 1" you can download the pdf file and try to cover as much as possible.

 

if my answer helped you kindly mark it helpful 

Swarup Patra
Kilo Guru

(function executeRule(current, previous /*null when async*/) { // http method can be null, if we upgrade from a previous release or with executing existing bussiness rule // which does not set http method. In those cases if function name is a valid http method we use it // if the function name is invalid some random option shown in UI. if ((!current.isValidField('http_method') || current.http_method.nil()) && !current.function_name.nil()){ var fName = current.function_name; if (fName == 'put' || fName == 'get' || fName == 'delete' || fName == 'post') current.http_method = current.function_name; else //This means an existing record with invalid http method as function name. gs.addErrorMessage("Invalid record. If HTTP method is not present, Name should be an HTTP method."); } })(current, previous); nowKB.com

Swarup Patra
Kilo Guru

The code you provided seems to be trying to retrieve a value from a field named 'u_fake' from the current record and then concatenate 'op' to the display value of that field. However, there are a few potential issues with this code: 1. The variable 'fake' is assigned the value of 'current.u_fake'. This implies that 'u_fake' is a field in the current record. If 'u_fake' is not a field in the current record, this will result in an error. 2. The method 'getDisplayValue()' is used on 'fake'. This method is used to get the display value of a field. If 'u_fake' is not a reference field, this method may not return the expected result. 3. The variable 'fake2' is assigned the value of 'op' concatenated with the display value of 'fake'. If 'fake' does not have a display value, 'fake2' will be assigned the value 'op'. Here's a corrected version of the code: javascript if (current.isValidField('u_fake')) { var fake = current.getValue('u_fake'); var fake2 = 'op' + fake; } In this version, the code first checks if 'u_fake' is a valid field in the current record. If it is, it retrieves the value of 'u_fake' and assigns it to 'fake'. Then it concatenates 'op' with 'fake' and assigns the result to 'fake2'. nowKB.com

cloudops
Tera Expert

No, the code you provided is not correct. Here's the correct way to do it:

- First, you need to check if the field 'u_fake' exists in the current record.
- Then, you can get the display value of 'u_fake' and concatenate it with 'op'.
- The correct code should look like this:

javascript
if (current.isValidField('u_fake')) {
var fake = current.u_fake;
var fake2 = 'op' + fake.getDisplayValue();
} else {
gs.addErrorMessage('Field u_fake does not exist');
}


Here's the breakdown:

- current.isValidField('u_fake'): This checks if the field 'u_fake' exists in the current record.
- var fake = current.u_fake;: This gets the value of 'u_fake' from the current record.
- var fake2 = 'op' + fake.getDisplayValue();: This concatenates 'op' with the display value of 'u_fake'.
- gs.addErrorMessage('Field u_fake does not exist');: This displays an error message if 'u_fake' does not exist.

 

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai