- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 03:39 PM
I'm doing these exercises in my personal developer instance to improve my ServiceNow skills. I'm working on this exercise: "Set up a record producer for the incident table that contains a 'Caller' and 'Configuration item' reference fields the same as your incident form. Automatically populate these fields onto an incident record without using any scripting."
Personal developer instances come with a record producer for incident out of the box, but they don't have those two fields. I created the two fields with the 'Map to field" checkbox checked and with the corresponding field selected. While the Configuration item field works just fine, the Caller field keeps getting overridden by the logged in user once the incident is actually created. There are no catalog UI polices for record producers and only 10 catalog client scripts total, none of which would seem to be causing this. Any advice on what might be going on and how to fix it would be appreciated.
Thanks
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2015 01:34 PM
Hey Robert,
There's only a few things that can be acting on the data once it's been submitted. You're going through a Record Producer, so I'd check the Script on the Record Producer (in the "What it will contain" section). By default, the "Create Incident" out-of-box record producer script looks like:
var isMobile = GlideMobileExtensions.getDeviceType() == 'm';
var link = isMobile ? '#/!list/incident/q:active=true%5Ecaller_id=javascript:gs.user_id()%5EEQ' : 'home.do';
var s = 'This incident was opened on your behalf<br/>';
s += 'The IT department will contact you if they need any further information<br/>';
if (isMobile)
s += 'You can track status from this <a href="' + link + '">List</a> <br/>';
else
s += 'You can track status from the <a href="' + link + '">Homepage</a> <br/>';
gs.addInfoMessage(s);
current.contact_type = 'self-service';
current.caller_id = gs.getUserID();
if (producer.comments.length > 80)
current.short_description = producer.comments.substring(0, 79);
else
current.short_description = producer.comments;
Line 13 shows the caller being set to the currently-logged-in user. If you copied this producer's script, and modified it for your needs, you may have missed that line.
After it goes through this script, the only other thing acting on the submitted Incident before it gets saved to the database will be business rules. You can set a Before business rule with a really low order, on Incident, Before insert, which simply logs the caller_id. That will tell you wether the caller_id is getting changed *before* business rules are invoked, or after/during business rule processing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 09:56 AM
Cory, I'm having the inverse issue on a different field. I have the 'node' field listed as a Reference on an extended version of the incident table. When submitting through the form, the node value clears unexpectedly on a submit. When I go back into the record using the form, I can update the node value successfully. However, when I use the Record Producer, the field stays populated on save/submit. I've tried Field Watcher, but it's not telling me much of anything. I've scoured the Business Rules with no success. Any other place I should look?
Thanks,
Charlie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 11:05 AM
Hi Charlie,
If this field is cleared out when you click the Submit button- before the form is actually submitted, then you have a client-side script clearing it. I'd check the onSubmit Client Scripts for that table. Something is clearing that field, probably with a call like:
function onSubmit() {
if (g_form.isNewRecord())
g_form.setValue('node', '');
}
Thanks
Cory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 12:33 PM
Hey Cory,
Just to confirm, I created a Business Rule to run first after an insert. I set it up to add a value to a string field if Node was not empty. Ran a test and no value was inserted. I changed the Rule to run if Node was empty. Ran another test and the value inserted. I just wanted to prove to myself Node is blank when the Business Rules fire. However, I've now searched all of the active onSubmit Client Scripts and found no reference to the Node field. It sounds like a perfectly reasonable solution, but my system doesn't feel like being reasonable. Any other suggestions?
Thanks,
Charlie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2016 07:07 AM
Hi Charlie,
Your message is a little ambiguous, so I want to make sure that the rule you created has an Order of 1, it's set to run before, and the insert box is checked. Are all of those true?
The order of operations when you are filling out and submitting a form are:
1. Any onLoad client scripts and UI Policies when the form loads.
2. onChange client scripts, when fields on the form are changed by the user.
3. onSubmit client scripts.
4. The UI Action script for the button/menu item used to submit (if client-side)
Now the data goes to server, and the order is:
1. The UI Action script for the button/menu item used to submit (even if marked as a client-side UI Action, this script will be evaluated. thats why you see mixed server-and-client code in the same UI Action in some cases)
2. Before business rules with order less than 1000 are run.
3. Engines are run (workflow, notification, data policy, approval, etc) are run.
4. Before business rules with order greater than or equal to 1000 are run.
5. After business rules with order less than 1000
6. More engines are run (text index, role sync, update_sync, etc)
7. After business rules with order greater than or equal to 1000
8. Async business rules are thrown into the scheduler queue to be picked up and run asynchronously
So the task is to check the value of those fields at each transition point and find out where it goes from correct -> incorrect. I would probably start with an onChange client script on that field which logs when the value changes, and what it changes to. Then I'd add an onSubmit script that logs the value of the field at submit time. I'd likewise add logging (client-side or server-side, or both- depending on the UI Action being used) that again checks the value of the field. If the UI Action is complicated, you may want to log both at the start of whatever complex script the action is running as well as at the end.
Find the transition from correct -> incorrect and that will tell you where to look for the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2016 01:31 PM
Cory,
That logic makes perfect sense. I was able to get an onLoad and an onSubmit client script to fire. When starting a new ticket, the onLoad alert displays nothing for the Node. I fill out the form, including the Node field, then submit. The onSubmit alert shows the sys_id value for the Node entered. It seems like the value makes it to at least that step. I then created a 'before' Business Rule to trigger when "Node is Empty" at order number 10 (server step #2 above). The rule fired, so I'm assuming that means the Node value has been cleared by that step. Do those tests seems valid? If not, what should I do differently? If they are testing accurately, and I have no clear reference to the Node field in any UI Action, how do I turn on logging to best help me see the values as they are passed to the server for submission?
Thanks so much for taking the time, Cory. I appreciate the hand holding.
Charlie