
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2019 07:07 PM
I'm hoping that someone might be able to help me with the correct way to pass values to a new record producer in a script. I'm sure it's something with the way that I have it written currently that just isn't processing correctly.
For background I have a UI Macro and UI Formatter that allows me to place a button to create a new record in a form (rather than the header). When clicked, the button builds a URL that links to a service catalog item, and passes the sys_id of the current record to populate a one of the variables. This is working as expected.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
.iotd .btn-success {
padding:5px !important;
width:140px !important;
background-color:#278efc !important;
border-color:#0e81FC !important;
margin-bottom:10px;
}
</style>
<g2:evaluate var="jvar_new_record_link" jelly="true">
// Build the URL to take to the new record producer; pass table name and sys id in the url
var params = 'sysparm_original_record=' + current.sys_id.toString();
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=48d98d4e1b088c108b96fee58d4bcb78';
var recordLink = (url + '&' + params);
recordLink;
</g2:evaluate>
<a href="$[jvar_new_record_link]" class="btn btn-success" target="_blank">New Example Record</a>
</j:jelly>
I then have another variable on the catalog item, a lookup select box that is configured as shown below:
This is also working as expected, and when I select the record type from the drop down and submit, it created the correct type of record on the correct table.
Now the issue I'm having though is that when I try to set certain values on the new record that is created, those values aren't passing over.
var newGR = new GlideRecord(producer.record_type);
newGR.initialize();
switch(producer.record_type) {
case 'u_record_type_a':
newGR.u_original_record = original_record;
newGR.u_short_description = 'Record Type A';
break;
case 'u_record_type_b':
newGR.u_original_record = original_record;
newGR.u_short_description = 'Record Type B';
break;
case 'u_record_type_c':
newGR.u_original_record = original_record;
newGR.u_short_description = 'Record Type C';
break;
}
var newSysID = newGR.insert();
var url = 'nav_to.do?uri=' + producer.record_type + '.do?sys_id=' + newSysID;
producer.redirect = url;
current.setAbortAction(true);
I'm sure it's something simple that I'm just not writing correctly. Any help is greatly appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2019 12:16 PM
Found the solution: Everywhere in the script where it calls (producer.record_type); actually needs to be formatted as (producer.record_type + '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2019 08:06 PM
You have no default value in your switch statement, I would set one and use it for debugging.
If you get the default value passed across every time, then I would hazard a guess that producer.record_type is not matching your cases as expected.
I would start there and add further steps such as console output messages for debugging, even trying producer.record_type.toString() to see if you have type issues.
There could be numerous problems, it would be good to see some debugging and possibly some error messages if you can produce any.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2019 08:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2019 10:39 AM
Ok, so I added an info message line to see what values are being shown for a few things and changed the script to:
var newGR = new GlideRecord(producer.record_type);
newGR.initialize();
switch(producer.record_type) {
case 'u_record_type_a':
newGR.u_original_record = producer.original_record;
newGR.u_short_description = 'Record Type A';
break;
case 'u_record_type_b':
newGR.u_original_record = producer.original_record;
newGR.u_short_description = 'Record Type B';
break;
case 'u_record_type_c':
newGR.u_original_record = producer.original_record;
newGR.u_short_description = 'Record Type C';
break;
}
var newSysID = newGR.insert();
var sd = 'Test Short Description'
var url = 'nav_to.do?uri=' + producer.record_type + '.do?sys_id=' + newSysID;
gs.addInfoMessage(producer.original_record + ' ' + sd + ' ' + producer.record_type);
producer.redirect = url;
current.setAbortAction(true);
The info message displayed after submitting shows the sys_id of the original record, the test short description string and the selected record type correctly, but the actual field values on the new record aren't set and are blank. If the values are being correctly interpreted, what can cause that not to be passed or set on the new record?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2019 12:16 PM
Found the solution: Everywhere in the script where it calls (producer.record_type); actually needs to be formatted as (producer.record_type + '');