Convert variable data to lowercase
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2015 09:24 AM
We have a string variable that we'd like to either force the data entered to be lowercase or either convert the information to lowercase once the record producer is submitted. This variable is populating the cmdb_ci on a change request.
Here's part of the script from the record producer. We're opening a change request and needing the server CI's that's being keyed in on the variable to be lowercase. The group didn't want the variable to be a reference field (long story).
current.cmdb_ci.setDisplayValue(producer.tempservername);
Tried the two below but didn't work:
//current.cmdb_ci.setDisplayValue(producer.finalsrvname.toString().toLowerCase().replace(/\s/g, '').trim());
//current.cmdb_ci.setDisplayValue(producer.finalsrvname.toLowerCase());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2015 01:13 PM
Woah. So you can manipulate the short_description but not the cmdb_ci reference field?
Are you doing any kind of server name validation?
I wonder if it is trying to set an invalid name from the string variable on the form to the reference variable on change. I think the logs would say something about this too (something something is undefined something something). The server name would have to exist in the referenced table.
You could try doing a lookup and returning a valid sys_id:
current.setValue('cmdb_ci', lookup(producer.finalsrvname.toLowerCase()));
function lookup(d) {
var server_lookup = new GlideRecord('cmdb_ci_server');//or whatever you server table is
server_lookup.addQuery('name', d);
server_lookup.query();
if(server_lookup.next()) {
return server_lookup.sys_id;
}
gs.log("NO SERVER NAME OF " + d + " FOUND!!");
return;
}
Also check your logs for errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2015 09:31 AM
Hello Andrea,
The toLowerCase method should work.
Try using setValue instead of setDisplayValue, see if it works.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2015 10:12 AM
try this
var FinalName = producer.finalsrvname + "";
current.cmdb_ci = FinalName.toLowerCase();
or
current.cmdb_ci.setValue(FinalName.toLowerCase());